PHP number_format gotcha

Posted by Andrew McCombe on Sat Dec 19, 2009

Be careful when doing any kind of calculations with numbers that have been passed through PHP’s number_format function as they can lead to unexpected results. The problems lie with the thousands separator (or the decimal separator if you use anything other than ‘.’). Here’s an example:

The issue is that the calculation ignores everything after the thousands separator ‘ , ‘.