Sorry that this is off M2 topic. There is still no other decent CF
forum on GG.

I just ran into a problem for the first time.

I have a banking-type application that stores "Decimal" type numbers
in MySQL with two decimal places (  Decimal(10,2)  ).

I just wrote a simple script which queries the DB, pulls out some
decimal numbers, and adds them and spits out the result. I got:

2292.95 + 51.05 = 2344
2344 + 77.30 = 2421.3
2421.3 + -2421.30 = 4.54747350886E-013
4.54747350886E-013 + 99.61 = 99.61
99.61 + 99.61 = 199.22
199.22 + 48.43 = 247.65
247.65 + 77.30 = 324.95

Notice the 4.54747350886E-013.  It appears that cold-fusion is doing
floating point subtraction in this case. I can't believe that in all
my years of CF, I've never ran into this issue. I tried using JavaCast
to Double and BigDouble around all my operands, but no cake. In the
end, I wrapped the operation in PrecisionEvaluate(...) and I get the
correct results. Apparently it uses the Java BigDecimal type.

2292.95 + 51.05 = 2344.00
2344.00 + 77.30 = 2421.30
2421.30 + -2421.30 = 0.00
0.00 + 99.61 = 99.61
99.61 + 99.61 = 199.22
199.22 + 48.43 = 247.65
247.65 + 77.30 = 324.95

Two things that confuse me.  Why did casting as BigDouble not solve
this problem. Why did coldfusion chose "float" as the type, since the
MySQL type was NOT float, it was Decimal(10,2). I did a GetMetaData()
on the query, and the numeric columns have "TypeName" = "DECIMAL" as
they should.

Weird.  Thanks for any insight!

-Brian

-- 
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en

***New URLs as of April 29th, 2010***
SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

Reply via email to