0

I want to create a function that for input 2.675 it returns 2.70 and for input 2.653 it returns 2.65. So basically I want to round a number to decimals, unless on hundredths position there's '5', then I want to round it to hundredths. Is there any clever way to do it, rather than doing it with if statements and checking what number is on hundredths position?

B.Mat
  • 85
  • 1
  • 8
  • Note that JavaScript handles only floats with decimal point full stop and not comma. So you need to have a display version - for example `let showNumber = myFloat.toFixed(2).replace('.',',');` – mplungjan Jun 28 '23 at 10:45
  • @mplungjan I have it with full stop, edited the question, thanks :) – B.Mat Jun 28 '23 at 10:48
  • so then my comment is no longer needed. Please read the dupe and delete the question – mplungjan Jun 28 '23 at 10:50

0 Answers0