0

How am I to get second decimal place 0?

For example:

15.296326 => 15.30
15.245152 => 15.20

I have tried toFixed() and Math.Floor but could not get the expected answer.

VisioN
  • 143,310
  • 32
  • 282
  • 281
Prajwol Onta
  • 1,448
  • 5
  • 21
  • 48

1 Answers1

3
function roundFloat(n) {
    return (Math.round(n * 10) / 10).toFixed(2);
}

roundFloat(15.296326);  // "15.30"
roundFloat(15.245152);  // "15.20"
VisioN
  • 143,310
  • 32
  • 282
  • 281