To round a value to the nearest multiple of x:
function roundTo(value:Number, to:Number):Number {
return Math.round(value / to) * to;
}
Example:
roundTo(8, 5); // 10
roundTo(17, 3); // 18
var a:Number=0.123456789;
trace(a); // 0.123456789
trace(a.toPrecision(4)); // 0.1235
trace(a.toFixed(4)); // 0.1235
trace(a.toExponential(4)); // 1.2345e-1
trace(a.toString(16)); // 0 - works for integer part only
var b:Number=12345678.9876543; // a bigg...