Skip to main content
Participant
March 21, 2013
Question

Coldfusion 8,9,10 errors during simple calculations

  • March 21, 2013
  • 1 reply
  • 547 views

We found strange issue during simple calculations. When trying to calculate:

1089.11 + 97.63 - 1186.74

we are receiving:

-2.27373675443E-013

but this value shoud be 0 (zero). Please try the following in your CF:

<cfoutput>

#1089.11 + 97.63 - 1186.74# (should be 0)<br />

#1079.11 + 97.63 - 1176.74# (should be 0)<br />

#1079.11 + 107.63 - 1186.74# (should be 0)<br />

#1189.11 + 97.63 - 1286.74# (should be 0)<br />

#1089.11 + 97.63 - 1186.64# (should be 0.10)<br />

#2089.11 + 97.63 - 2186.74# (should be 0)<br />

#3089.11 + 97.63 - 3186.74# (should be 0)<br />

</cfoutput>

It's strange and we are not sure how to deal with this issue. Of course we can use Round, we can use some other methods, but we don't want to review all our applications to check if such situation occured...

Pawel Dulak


This topic has been closed for replies.

1 reply

Participant
March 21, 2013

The same situation for PHP and JavaScript. WTF?

Pawel Dulak

Participating Frequently
March 21, 2013

google Floating Point Arithmetic rounding errors, this is a common problem

Participant
March 21, 2013

OK, now it's clear - there is a problem during conversion to binary (binary floating point number).

We have to implment additional security here and there...

Thanks!

Pawel Dulak