What is up with this in ColdFusion's DecimalFormat() function? How do I get the correct result? -


<cfset number1 = 20.5/80 * 100 /> <cfset number2 = 18.125 /> <cfset number3 = 6.875 />  <cfoutput> decimalformat(#number1#): #decimalformat(number1)#<br /> decimalformat(#number2#): #decimalformat(number2)#<br /> decimalformat(#number3#): #decimalformat(number3)# </cfoutput> 

outputs:

decimalformat(25.625): 25.62

decimalformat(18.125): 18.13

decimalformat(6.875): 6.88

rather outputing:

decimalformat(25.625): 25.63

decimalformat(18.125): 18.13

decimalformat(6.875): 6.88

it seems variable result of mathematical calculation makes decimalformat() behave differently. quick fix, without digging java?

i think problem not decimalformat(), typical floating-point rounding errors.

see: precisionevaluate()


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -