-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
  • 57,719
  • 27
  • 114
  • 156
Liam
  • 9,725
  • 39
  • 111
  • 209

2 Answers2

0

What's need of jquery

var newCostDiff = 0.135;
Math.round(newCostDiff *100)/100; //returns 0.14
Mritunjay
  • 25,338
  • 7
  • 55
  • 68
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
  • 32,252
  • 11
  • 87
  • 108