PHP Division会自动将数字四舍五入 [英] PHP Division results in automatically rounded up number

查看:55
本文介绍了PHP Division会自动将数字四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的部门:

72/193

Excel给我的结果

0.373056994818653

PHP将其四舍五入

0.373056994819

我的问题是-我怎样才能使PHP为我提供确切的数字,而不是四舍五入?

解决方案

这不是精确与否的问题,它与精度有关. Wolfram Alpha 具有更高的精度.>

您需要更改您的php配置的精度以适应小数点后需要多少个单位.我找不到PHP所能提供的最大精度,但是我确信这是有限制的.

I have a simple division:

72 / 193

Excel is giving me result of

0.373056994818653

While PHP round it up to

0.373056994819

My question is - how can I make PHP to give me the exact number instead of a rounded up one?

解决方案

It isn't a question of being 'exact' or not, it is about precision. Wolfram Alpha has a much larger precision for your answer.

You need to change the precision of your php configuration to suit how many units you need after the decimal. I cannot find the largest precision PHP has to offer, but I'm sure there is a limit.

这篇关于PHP Division会自动将数字四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆