For example the following code returns the value 10:
- Code: Select all
Math.round(10.455)
I want round this to a two decimal point number. I suppose the return the value of 10.46
Thanks
Math.round(10.455)
var myNum = 10.455;
myNum = myNum.toFixed(2);
ROCLASI wrote:
- Code: Select all
var myNum = 10.455;
myNum = myNum.toFixed(2);
This should do it.
Although for me it returns 10.456 (!).
Changing the input-number to 10.4551 makes it work correctly.
Seems like a bug to me.
return parseFloat((19 /100 * 487.50).toFixed(2));
return (19 /100) * 487.50
Math.round(10.455*100)/100
//format a number to specification (or to have a defined fraction)
var textalNumber = utils.numberFormat(16.749, 2); //returns 16.75
var textalNumber2 = utils.numberFormat(100006.749, '#,###.00'); //returns 100,006.75
var numToRound = arguments[ 0 ];
var decimalPlaces = arguments[ 1 ];
var multiplier = Math.pow( 10, decimalPlaces );
return Math.round (multiplier * numToRound ) / multiplier;
SteveInLA wrote:As stated by Jan Blok in the post referenced by Enrico, the toFixed method returns a string
HJK wrote:that's true, but the toFixed function does weird stuff something.
(or I'm using it wrong. so I recommend for currency NOT to use the parseFloat((19 /100 * 487.50).toFixed(2)) function.
- Code: Select all
var myNum = 10.455;
myNum = myNum.toFixed(2);
This should do it.
Although for me it returns 10.456 (!).
Changing the input-number to 10.4551 makes it work correctly.
Seems like a bug to me.
Math.round(10.455*100)/100
Users browsing this forum: No registered users and 13 guests