在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:
www.php/manual/en/ref. bc.php
还是GMP函数,尽管它们似乎只是整数.
Or the GMP functions, although they seem to be integer only.
www.php/manual/en/ref. gmp.php