I used below two methods :
Number.prototype.myRound = function (decimalPlaces) {
var multiplier = Math.pow(10, decimalPlaces);
return (Math.round(this * multiplier) / multiplier);
};
alert((239.525).myRound(2));
Mathematically alert should be 239.53
but its giving 239.52
as output.
So i tried using .toFixed()
function & i got proper answer.
But when i try to get answer for 239.575
it gives again wrong output.
alert((239.575).toFixed(2));
Here output should be 239.58
instead its giving 239.57
.
This error creating a bit difference in final output. So can anyone help me to sort this out?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…