Convert exponential number presented as string to a decimal

后端 未结 3 459
庸人自扰
庸人自扰 2020-12-11 17:55

Let\'s suppose I have a string that contains \"7.2769482308e+01\" (this number came from 3rd party software, I cannot control the format).

What is t

相关标签:
3条回答
  • 2020-12-11 18:11

    Here is a very cheap one: $float = "7.2769482308e+01" + 0;

    0 讨论(0)
  • 2020-12-11 18:24

    What about a simple cast to a float value ?

    $string = "7.2769482308e+01";
    $float  = (float) $string;
    
    0 讨论(0)
  • 2020-12-11 18:24

    I had success using number_format(1.2378147769392E+14, 0, '', '') which was originally provided by this question.

    This also works when the value is a string, like so: number_format("1.2378147769392E+14", 0, '', ''). Go ahead, give it a try.

    0 讨论(0)
提交回复
热议问题