Default Number of Decimal Places to Output in PHP

前端 未结 6 1354
执念已碎
执念已碎 2020-12-18 13:37

I do my php work on my dev box at home, where I\'ve got a rudimentary LAMP setup. When I look at my website on my home box, any numbers I echo are automatically truncated t

6条回答
  •  借酒劲吻你
    2020-12-18 14:16

    And when you can't rely on the PHP configuration, don't forget about number_format() which you can use to define how a number is returned, ex:

    // displays 3.14 as 3 and 4.00 as 4    
    print number_format($price, 0); 
    // display 4 as 4.00 and 1234.56 as 1,234.56 aka money style
    print number_format($int, 2, ".", ","); 
    

    PS: and try to avoid using money_format(), as it won't work on Windows and some other boxes

提交回复
热议问题