Re: [Flashcoders] Formatting number to 2 decimal places

2007-09-14 Thread Rich Shupe
function roundToDecimal(val:Number, places:int):Number { var factor:int = Math.pow(10, places) return Math.round(val * factor) / factor; } trace(roundToDecimal(Math.random(), 1)); trace(roundToDecimal(Math.random(), 2)); trace(roundToDecimal(Math.random(), 3)); __

Re: [Flashcoders] Formatting number to 2 decimal places

2007-09-14 Thread Andrei Thomaz
and this Math.round(number * 100) / 100; ? []'s andrei On 9/14/07, Paul Steven <[EMAIL PROTECTED]> wrote: > > I would be interested to know how people format numbers in AS3 to 2 > decimal > places. > > I am currently using the following but it does not always appear to work: > > var displayP

[Flashcoders] Formatting number to 2 decimal places

2007-09-14 Thread Paul Steven
I would be interested to know how people format numbers in AS3 to 2 decimal places. I am currently using the following but it does not always appear to work: var displayPercentageValue:Number = Math.round(percentageValue / .01) * .01; Sometimes it seems to be displaying correctly, sometimes it d