我如何在 php 中舍入并保留两个零
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7493305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:48:20 来源:igfitidea点击:
how do i round in php with keeping the two zeros
提问by Matt Elhotiby
I have this php
我有这个 php
<?php echo round($price, 2); ?>
and the $price
maybe 1.0000
和$price
可能1.0000
i want 1.00
but i get only 1
我想要,1.00
但我只得到1
any ideas
有任何想法吗
回答by John Godspeed
回答by Tim Cooper
回答by Louis
number_formatis your best bet.
number_format是您最好的选择。
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
Example:
例子:
<?php echo number_format(1.0000, 2, '.', ','); ?>