0

I am trying to figure out how to prevent rounding of numbers when it comes to decimal precisions. I am currently using the .toFixed(2) method to only display two decimal places after the decimal but it is also rounding this figure. For example, if I had a number 19.528 the method Number(19.528).toFixed(2) will yield 19.53 instead of displaying the value 19.52 . Is there anyway or other method to take care of it so that the number does not round?

Kimbo
  • 191
  • 1
  • 10
  • Number(num.toString().slice(0, (num.toString().indexOf("."))+3)) – Rohit Pratap Oct 14 '22 at 14:46
  • 1
    [MDN: math.floor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) - the trick is to multiply by 100 first the divide by 100 to get the 2 dp. – freedomn-m Oct 14 '22 at 14:47

0 Answers0