最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

用PHP进行精确的实数运算

SEO心得admin30浏览0评论
本文介绍了用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:

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

发布评论

评论列表(0)

  1. 暂无评论