Bug in NumberFormat() in 12th decimal place when using BigDecimals (and doubles!)

Hey, it happens in the 12th position with “Precise Math” turned off, too.

I just turned it off, then made a version of the test code that only uses 12 places after the decimal, and the problem still happens:

<cfset my_number = 0.111111111111>
<cfset my_formatted_number = NumberFormat(my_number,"0.000000000000")>
<cfdump eval="my_number">
<cfdump eval="my_formatted_number"><hr>

<cfset my_number = 0.999999999999>
<cfset my_formatted_number = NumberFormat(my_number,"0.000000000000")>
<cfdump eval="my_number">
<cfdump eval="my_formatted_number"><hr>

<cfset my_number = 0.415661687696>
<cfset my_formatted_number = NumberFormat(my_number,"0.000000000000")>
<cfdump eval="my_number">
<cfdump eval="my_formatted_number">

The formatted numbers output are these (run it yourself to verify):

0.111111111112
1.000000000000
0.415661687697

So it even happens when using doubles, not just BigDecimals. Pretty serious bug that can cause hard-to-notice numeric inaccuracies. FYI.

1 Like