PDA

View Full Version : rounding to 2 decimal places (dollars and cents)


mperrah
09-09-2001, 07:25 PM
I am building a shopping cart http://www.mperrah.com/tulip/archive/index.html
(Click the images to get to the cart.)
I multiply the sales tax and get 3 or more decimals places for the result.
Is there a way to round up to 2 decimals
ie ($123.46)
not ($123.456...)
I can send the .fla file to anyone interested

Jesse
09-10-2001, 06:27 AM
http://www.actionscripts.org/forums/search.php3?query=round+decimal+number&forumchoice=-1&booleanand=yes&searchin=all&searchdate=-1&searchuser=&searchdateline=&exactname=yes&action=dosearch&getdaily=&pagenum=

search = good

ushka
04-24-2008, 06:07 PM
Math.round(number*100)/100
http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15542

USFbobFL
04-14-2010, 06:08 PM
Here's a nice little function that rounds to any number of decimal places.

private function roundDec(numIn:Number, decimalPlaces:int):Number {
var nExp:int = Math.pow(10,decimalPlaces) ;
var nRetVal:Number = Math.round(numIn * nExp) / nExp
return nRetVal;
}

uday_sgh
09-11-2011, 06:21 PM
Here is very simple code to round up the decimal as below:

var cost = 5.2382565
var roundCost = cost.toFixed(2)
trace(roundCost);
// Here you will get the output: 5.24

You change the toFixed value as per you need instead of 2.

I hope it will resolve your problem if you have any other issue please let me know.