如何在 PHP 中舍入小数以匹配 Google 的结果
我正在尝试开发一个 php 代码来以与 Google 计算器返回结果相同的方式匹配小数,所使用的数学是 3.14159265 (pi) * 三位数,例如在 php pi * 123 中返回 386.41589595,但 Google 返回 386.415896。我尝试了ceil、round等功能,没有效果。我需要谷歌数学用来四舍五入/减少 pi * 数字的确切方法,
这是因为将用于的应用程序仅使用以谷歌计算器的方式建模的 pi * 数字结果返回准确的结果,任何帮助将不胜感激。这里有一些其他的例子,我试图弄清楚用什么数学来四舍五入,但到目前为止我很不幸。
pi * 205 = 644.026494 (谷歌结果,我想要/需要,抓取谷歌是不够的,我需要开发一个本地php方法来获得这个确切的结果,其中“205”通常是一个随机数三位数,仅在本例中用作示例)
在 php 205*pi = 644.02649325 中,我需要句点后面的数字与结果完全匹配谷歌的计算器返回。
我该如何实施呢?基本上我需要谷歌返回 pi * 数字(三位数)的确切结果,而不必依赖谷歌(抓取结果)。在 php 中一定有某种方法可以做到这一点,但到目前为止我的实验还没有结果。我不是最好的数学学生。我希望得到一些帮助,理查德。谢谢。
I am trying to develop a php code to match decimals in the same exact way which Google calculator returns results, the math being used is 3.14159265 (pi) * three digits, for example in php pi * 123 returns 386.41589595, however Google returns 386.415896. I have tried the ceil, round, and other functions to no avail. I need the exact methodology Google math uses to round/reduce its numbers for pi * digits
This is because an application this will be used for only returns accurate results using pi * digit results modelled in Google calculator's fashion, any help would be appreciated. Here are some other examples, I have tried to figure out what math is being used to round but I have been unfortunate so far.
pi * 205 = 644.026494 (Google results, which I want/need, scraping Google will not suffice, I need to develop a native php method of obtaining this exact result, where "205" is will usually be a random number three digit number, just using as example in this case)
in php 205*pi = 644.02649325, I need the numbers after the periods to match exactly the results Google's calculator returns.
How could I go about implementing this? Basically I need the exact results google would return for pi * digit (three digit number), without having to depend on Google (scraping the results). There must be some way to do this in php but the my experimentation has been fruitless thus far. I am not the best math student. I would appreciate some help, Richard. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用此
bcmul
函数将采用第三个参数作为精度参考这个
use this
this
bcmul
function will take third parameter as precisionrefer this
检查您的精度/近似设置。这应该适合你
Check your precision / approximation settings. This should work for you