Convert a string containing a number in scientific notation to a double in PHP

前端 未结 8 1716
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 08:18

I need help converting a string that contains a number in scientific notation to a double.

Example strings: \"1.8281e-009\" \"2.3562e-007\" \"0.911348\"

I wa

8条回答
  •  再見小時候
    2020-12-25 08:45

    function decimal_notation($float) {
            $parts = explode('E', $float);
    
            if(count($parts) === 2){
                $exp = abs(end($parts)) + strlen($parts[0]);
                $decimal = number_format($float, $exp);
                return rtrim($decimal, '.0');
            }
            else{
                return $float;
            }
        }
    

    work with 0.000077240388

提交回复
热议问题