如何在PHP中使用高精度小数 [英] How do I work with high precision decimals in PHP

查看:65
本文介绍了如何在PHP中使用高精度小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP创建数据库驱动的网站,并将数据存储在PostgreSQL数据库中(通过PDO访问),并且我将需要存储和处理高精度十进制数(在某些情况下,超过20个小数点后的数字).

I am trying to create a database-driven website with PHP and with data stored in a PostgreSQL database, (accessed with PDO) and I will be needing to store and manipulate high precision decimal numbers (in some cases, more than 20 digits after the decimal).

我计划在数据库中使用NUMERIC或DECIMAL数据类型存储此数据,以保持所需的高精度.

I am planning on using the NUMERIC or DECIMAL datatypes in my database to store this data, in order to maintain the high levels of precision needed.

使用PHP来(1)访问这些值,以及(2)对这样的高精度数字执行基本算术的最佳方法是什么?

What is the best way to use PHP to (1) access these values, and (2) perform basic arithmetic on such high-precision numbers?

我不想只使用浮点数,因为该数据类型可能不精确.

I don't want to just use floats, since that datatype can be imprecise.

谢谢!

推荐答案

查看 GNU多精度 BC Math 扩展.

这篇关于如何在PHP中使用高精度小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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