5

I was trying to display a number: 2893604342.00. But, when i am displaying it it is displayed as: -2893604342.

Following is the code snippet ...

avg += int(totalData[i][col.dataField]); 

I have even replaced it with Number, but it's still showing the same negative number.

Please let me know whether there is any problem with int or Number!

Shog9
  • 156,901
  • 35
  • 231
  • 235

4 Answers4

14

The maximum values are accessible through each numeric type's static properties:

  • Number.MAX_VALUE
  • uint.MAX_VALUE
  • int.MAX_VALUE

(Just trace 'em.)

someOne
  • 1,975
  • 2
  • 14
  • 20
JMHNilbog
  • 1,073
  • 1
  • 8
  • 13
5

integers in flash are 32 bits, so an unsigned int's max value is (2^32)-1, 0xffffff or 4294967295. a signed int's max positive value is (2^(32-1))-1 or 2147483647 (one of the bits is used for the sign). the Number type is 64 bits.

in order to guarantee space for your result, type the variable to Number and cast the result to Number (or not at all).

var avg : Number = 0; ... avg += totalData[i][col.dataField] as Number;

2

The largest exact integral value is 2^53, Remember ActionScript is ECMA at heart. Look for the operator ToInt32 for more info on that.

JP Silvashy
  • 46,977
  • 48
  • 149
  • 227
  • Hi , I guess we dont have that operator in ActionScript , I tried using Number which is quite bigger but still getting the same negative value. –  Aug 06 '09 at 13:40
2

Try casting it to a uint instead of an int

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237