Skip to main content
Participant
Mar 21, 2013 10:27 AM UTC
Question

Coldfusion 8,9,10 errors during simple calculations

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 is closed to new replies. Start a new post to keep the conversation going.

3 replies

Participant
Mar 21, 2013 10:35 AM UTC

The same situation for PHP and JavaScript. WTF?

Pawel Dulak

Translate
Participating Frequently
Mar 21, 2013 11:05 AM UTC

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

Translate
Participant
Mar 21, 2013 11:20 AM UTC

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

Translate