-2

I have a JavaScript function that returns the result of multiplications using decimal values (four digits after dot).

But, in some conditions, the result is a mess like this:

3.9050 * 9 = 35.144999999999996.

What should I do to normalize those results?

Paul Roub
  • 36,322
  • 27
  • 84
  • 93

1 Answers1

0

Use .toFixed(numberOfDecsYouWant)

var num = 3.9050 * 9;
console.log(num);  //35.144999999999996
console.log(num.toFixed(4))  //35.1450
kpucha
  • 729
  • 5
  • 12