I've been waffling on how to deal with currency display and math in PHP, and for a long time have been storing it in MySQL using the DECIMAL
type, and using money_format()
to format it for display on the web page. However, today I looked at the actual prototype:
string money_format ( string $format , float $number )
I'm a little confused now. All I've been told is, avoid floats for money! But here it is, the fundamental formatting function (say that five times fast), casting the input to a float. number_format()
does the same.
So my questions are:
Unless I'm dealing with fractional cents or trillions of dollars (and I'm dealing with neither), should I be concerned at all about displaying and storing (but never doing math on) currency that's been cast to a float? Will I ever come close to the area of having floating point inaccuracies change my figures?
If the answer to #1 is that I should indeed be concerned, then why is
money_format()
built this way?