[英]php round float number
I have read the documentation and have clear idea of round but i didn't find useful information to solve the problem. 我已经阅读了文档并且对解决方法有清楚的了解,但是我没有找到解决问题的有用信息。
The problem is i have float number which is let say 1.09 and i want to display it 2 instead of 1. if we use round function it display 1. Help me solve this problem. 问题是我有浮点数,可以说是1.09,我想显示2而不是1。如果我们使用取整功能,则显示1。请帮助我解决此问题。
MORE DETAILS... 更多细节...
$TotalPaidRemaining=1090;
$monthly_installments=1000;
$MakingNumberOfMonths=$TotalPaidRemaining/$monthly_installments;
echo round($MakingNumberOfMonths, 0, PHP_ROUND_HALF_UP);// it display 1. i want it display 2..
What i want is if the value after decimal point is greater than 0. For example 0.01. 我想要的是如果小数点后的值大于0。例如0.01。 I want to consider it as 1. 我想将其视为1。
Hope i am clear at my question. 希望我清楚我的问题。
You can use the ceil() php function instead of round(). 您可以使用ceil()php函数代替round()。 It will round up your values. 它将丰富您的价值观。 Docs: http://php.net/manual/en/function.ceil.php Example: ceil(1.09); // return 2
文件: http : ceil(1.09); // return 2
范例: ceil(1.09); // return 2
ceil(1.09); // return 2
You could use ceil($yourNumber)
, which will round the number to its next higher integer. 您可以使用ceil($yourNumber)
,它将数字四舍五入到下一个更高的整数。
Or you could use round($yourNumber + 0.499999999999999)
. 或者您可以使用round($yourNumber + 0.499999999999999)
。
Or you could use floor($yourNumber + 1)
, which rounds the number to its previous highest integer. 或者,您可以使用floor($yourNumber + 1)
,将数字四舍五入到其先前的最高整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.