I have a variable vAmount that I need to format as currency with commas and 2 decimal places. I can't find any kind of format function in actionscript. I'm using MX.
round decimals
Contributed by: Stuart S (stuartmx@xs4all.nl), 12/10/2001 (n=1523)
Here is a simple function that'll round a number of to any decimal place.
---------------------------------
Math.roundTo = function(num,dp){
var d = Math.pow(10,dp);
return Math.round(num*(d+0.00000001))/d;
};
--------------------------------
example:
Math.roundTo(1.2345,2)) //1.23
You can even use negative numbers for decimal places
Math.roundTo(12345,-2)) //12300
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.