-1

I have the following number

0.135

I'd like to round it to 2 decimal places, I'm using...

(newCostDiff/2).toFixed(2)

only this returns

0.13

Can anyvody advise me on how to do this?

tckmn
  • 55,458
  • 23
  • 108
  • 154
Liam
  • 9,537
  • 36
  • 106
  • 204

2 Answers2

0

What's need of jquery

var newCostDiff = 0.135;
Math.round(newCostDiff *100)/100; //returns 0.14
Mritunjay
  • 24,184
  • 7
  • 51
  • 67
0

You should first multiply the result by 10^(number of decimals), then round the number, than divide this number by 10^(number of decimals).

In this case:

Math.round((newCostDiff/2)*100) / 100;
Jerodev
  • 31,061
  • 11
  • 83
  • 102