0

If I subtract 300.7 - 245.8, it is displaying result as 54.89999999999998 and 400 - 364.7 as 35.30000000000001.

Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
Raghul
  • 213
  • 1
  • 5
  • 9
  • It is because Javascript does odd things with floats and math. you will need to round the number off or split the decimal place into an integer. for a fill description into this please see: https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript – MrPickles Jul 19 '18 at 08:17

1 Answers1

0

Use Math.round(num * 100) / 100 on your result, this should round it to 2 numbers.

Bart
  • 267
  • 1
  • 10
  • Is there any permanent solution. Because, i am using these subtraction concept in so many files. If i use this, i have to edit in all files – Raghul Jul 19 '18 at 07:35
  • You can make a function called substract and use that every time you want to subtract something. Then place this round down in the method. – Bart Jul 19 '18 at 07:38