0

I am having a problem when you perform an equation similar to this one:

let result = (num1/num2) - 1;

An example for that one is (157.23 / 120) -1, javascript gives a result of 31.024999999 but a regular calculator or calculator application give a result of FIXED 31.025

Is there any way how to avoid this issue?

Star
  • 161
  • 6
  • 15
  • use toFixed method of Javascript. Number( result.toFixed(2) ); https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed – Partha Roy Jan 30 '20 at 07:38
  • You can use result.toFixed(3), where 3 is number of values after decimal. – beingyogi Jan 30 '20 at 07:39

0 Answers0