Friday, January 15, 2010

AS3: Remove fractional part in Number

Give a one line expression to remove the fraction part from a Number variable in AS3. Hint: should work for positive as well as negative numbers, and more than 32-bit numbers.

1 comment:

Kundan Singh said...

value = (value < 0 ? Math.ceil(value) : Math.floor(value))

Note that the other solutions of (1) typecast to int() does not work for more than 32-bit numbers, because int is 32-bits whereas Number can be larger in AS3, and (2) Math.floor(value) doesn't work for negative numbers because floor(-4.3) == -5.