用PHP进行精确的实数运算 [英] Doing exact real number arithmetic with PHP

查看:107
本文介绍了用PHP进行精确的实数运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中对表示实数的字符串进行基本算术运算的最快,最简单的方法是什么?我有一个字符串,表示要在其上操作的MySQL的DECIMAL值,然后将结果返回到数据库.我想避免浮点实数表示法引入的错误.

What is fastest and most easy way of making basic arithmetic operations on strings representing real numbers in PHP? I have a string representing MySQL's DECIMAL value on which I want to operate and return the result to a database after that. I would like to avoid errors introduced by floating-point real number representation.

是否有一些标准库,例如Python的十进制?您是否可以推荐任何FOSS库?

Is there some standard library like Python's decimal? Are there any FOSS libraries you can recommend?

致谢

推荐答案

您可以使用BC数学函数:

You could use the BC math functions:

http://www.php.net/manual/en/ref. bc.php

还是GMP函数,尽管它们似乎只是整数.

Or the GMP functions, although they seem to be integer only.

http://www.php.net/manual/en/ref. gmp.php

这篇关于用PHP进行精确的实数运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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