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
  • 138,460
  • 30
  • 271
  • 271
Prajwol Onta
  • 1,358
  • 5
  • 19
  • 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
  • 138,460
  • 30
  • 271
  • 271