Return to Snippet

Revision: 49662
at July 27, 2011 22:23 by adrianparr


Initial Code
var num:Number = 98.76543210;

var num2:Number = Number(num.toFixed(2));
trace("num2: " + num2);
// OUTPUT
// num2: 98.77

var num3:Number = Number(num.toFixed(1));
trace("num3: " + num3);
// OUTPUT
// num3: 98.8

var num4:Number = Number(num.toFixed(0));
trace("num4: " + num4);
// OUTPUT
// num4: 99

var num5:Number = Number(Math.abs(num));
trace("num5: " + num5);
// OUTPUT
// num5: 98.7654321

var num6:Number = Number(int(num));
trace("num6: " + num6);
// OUTPUT
// num6: 98

var num7:Number = Number(Math.round(num));
trace("num7: " + num7);
// OUTPUT
// num7: 99

var num8:Number = Number(Math.floor(num));
trace("num8: " + num8);
// OUTPUT
// num8: 98

var num9:Number = Number(Math.ceil(num));
trace("num9: " + num9);
// OUTPUT
// num9: 99

Initial URL

                                

Initial Description
Examples of different ways to truncate/round a decimal number.

Initial Title
AS3 Truncating Decimal Number

Initial Tags
number

Initial Language
ActionScript 3