How do I convert output of number_format back to numbers in PHP?

后端 未结 9 1541
星月不相逢
星月不相逢 2020-11-27 16:47

PHP can\'t recognize 1,200.00(generated by number_format) but only 1200.00,

What\'s the general solution for this problem?

9条回答
  •  长情又很酷
    2020-11-27 17:12

    The better way is to use the options in number_format function itself. The format is

    number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
    

    I.e. if you don't need the ',' in the formatted string make, it is like

    $num=23.33333
    echo number_format($num,2,'.','');
    

    If you need that as float then typecast the same to float

    $floatnum= (float) number_format($num,2,'.','');
    

提交回复
热议问题