首页 > 解决方案 > Is there any particular reason that PHP doesn't do bcadd() whenever + is used?

问题描述

Whenever I'm dealing with numbers in PHP which represent money, I'm forced to use bcadd() and the other functions in that "family", instead of simply using the nice symbols such as +, -, / and *.

The reason is something about "floats" being inaccurate for some reason. I've many times tried to understand why exactly this is, but I can't make any sense of it.

It would be much nicer to use the symbols instead of the BC Math functions.

Why aren't the floats just accurate instead? Or made into "numerics" if "floats" by their nature are inaccurate?

It's not a problem anymore because I know about this, but for most of my life when I'm coded PHP, I had no clue even about the existence of those functions, let alone the need to use them.

标签: phpfloating-pointnumbersbcbcmath

解决方案


推荐阅读