Saturday, July 6, 2013

AS3 and Big Numbers

I ran into a problem when transferring large numbers between the client and server. They would send me a number and when I sent it back to them it would be different. Turns out ActionScript 3 has problems with big numbers. Here is a quick example. The expected output would be 129090238754375001.


var string:String = "129090238754375000";


var number:Number = Number(string);


var nextNumber = number + 1;


trace(nextNumber);


Here are the variables after execution. Notice that both number and nextNumber are 129090238754375008.

And the output window:

So has a range of -2,147,483,648 to 2,147,483,647 and has a range of 0 to 4,294,967,295. While can represent integers outside the range of int and uint, it has precision limitations.
The solution in our case was that, since we were not doing any math and just using it as an identifier, we changed the server code to use a string instead. - Full Post

No comments:

Post a Comment