Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为需要计算,特别是除法的客户端构建一个 PHP 平台,以通过金钱来完成。这些计算需要精确到 0.01 美分。将货币乘以 10000 并转换为 INT 的正确方法是否正确,然后对这个数字进行计算?
我建议您使用正确/实际的浮点数进行所有计算(不要投射或转换它们),然后您可以稍后使用 2 个小数精度对其进行格式化。
仅使用number_format或round来显示结果。