Display float value w/o scientific notation

后端 未结 4 495
长发绾君心
长发绾君心 2020-11-27 20:00

When i make the following multiplication in PHP:

$ret = 1.0 * 0.000000001;

i get the result: 1.0E-9

I want to convert this result i

4条回答
  •  执念已碎
    2020-11-27 20:52

    You need to add precision specifier (how many decimal digits should be displayed for floating-point numbers). Something like this:

    echo sprintf('%.10f',$ret);  // 0.0000000010
    

    If you have no idea what number you should specify, just give it a big number and combine it with rtrim().

    echo rtrim(sprintf('%.20f', $ret), '0');  // 0.000000001
    

    The code above will strip any 0's from the end of the string.

提交回复
热议问题