How to make numbers not be shown in scientific form?

后端 未结 2 1107
礼貌的吻别
礼貌的吻别 2021-01-27 10:33

I want to write an array of floating point numbers into files



        
2条回答
  •  孤独总比滥情好
    2021-01-27 11:26

    You can use the number_format function to set a precision:

    Example:

    $mynum = 24.2837162893;
    $mynum = number_format($mynum, 2);
    echo($mynum);
    
    // Outputs 24.28
    

    So if you decide you want all your numbers to have 10 decimal places, you would just use $mynum = number_format($mynum, 10);.

    Also, see the sprintf() function for other formatting options.

    [EDIT]

    In your particular example, here is where you would use this function:

    
    

    As described in the other answer, float values are inherently imprecise. You have to decide what precision is important to you in your use case.

    Ref: http://php.net/manual/en/function.number-format.php

提交回复
热议问题