In PHP, I am writing an application which requires precision to 2 digits right of the decimal point for currency (eg: I care about 1.23 === 1.23
but no more right-side digits).
I am aware that floats are generally considered bad practice because they are imprecise with values based on the nature of converting from base 2 to base 10 right of the decimal point. However, in my research for a best practice for working with currency values, I saw some arguments that float is not good if you need precision greater than whole cent values. I clearly do not need greater precision that whole cent values.
So my questions, then, are:
- Is it worth going through the extra effort of storing the values as strings to be used with the
bcmath
library? - If using the
bcmath
lib, should I store the values in the MySQL db as strings ordecimal
that MySQL supports?
Thanks!