Thursday, April 29, 2010

Working with large numbers in ColdFusion

I just thought of sharing my friend's experience with managing large numbers using ColdFusion. They got an assignment that will manipulate numbers and things seem good at first. When the numbers started getting larger(20 digits), we had a problem. In CF, the limit of Integer is -2,147,483,648 and 2,147,483,647 (32-bit signed integers) and the calculations started giving unexpected results.
After quite a bit of Googling and posting in forums, they got the solution from a user in the Adobe forums. It is to use the Java Math object and convert the number to BigInteger. Here is the code: