toFixed() and/or toPrecision()

Alex Harui
Flex SDK Developer
Adobe Systems Inc.<http://www.adobe.com/>
Blog: http://blogs.adobe.com/aharui

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of jer_ela
Sent: Thursday, July 16, 2009 9:41 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: look for a actionscript function?



I assume that what you want to do is round to to decimal places.

If all you want to do is display the rounded number, you can use the 
NumberFormatter class. This can give you a string representation of the number 
rounded as you want it, which is fine for display.

If you need to actually round the number and use the rounded value in 
subsequent calculations, you can use the following function.

public function round(number:Number, decimals:int):Number
{
return Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals);
}

--- In flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, 
"markflex2007" <markflex2...@...> wrote:
>
> I have a number 0.3563567,I want to convert it to 0.36,which function can do 
> this?I check Math class at
> http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Math.html
>
> but I can not get right one.
>
> Thanks for your help
>
> Mark
>

Reply via email to