I am trying to do simple number rounding in javascript to round off values to 2 decimal places.(Excuse for poor english..)
After very little little research I found a solution which is as follows-
var num=1.234;
var result=Math.round(num*100)/100;
It's working fine in most of the cases except for one! If num conatins 1.345, mathematically after rounding off the result should be 1.34(When an even decimal (or any even number) is followed by a 5, you
round down. When an odd decimal is followed by a 5, you round up.
For example: 75.45 = 75.4, but 75.55=75.6)
But I am getting 1.35. So how can I get the desired result? Like when i pass 1.345, I get 1.34 and when I pass 1.335, I get 1.34
Because it's an API method I have almost idea as to what should I do. Can anyone help me out here..
Thanks in advance!!!