0

Is there a difference between bracket and no bracket for below case? The return result is different. If i do a .toFixed(2) to the value, it causes 1 cents difference.

var x  = ( 103.5 * 15 / 100  );
var x1 = ( 103.5 * ( 15 / 100 ));

alert(x); //15.525 => after round to 2 decimal : 15.53
alert(x1); //15.524999999999999 => after round to 2 decimal : 15.52
xsct
  • 21
  • 2
  • You can read more here [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken.) – Ricky Mo Oct 05 '21 at 04:13
  • In general, for numbers >= 1, do multiplication first to get the numerator as big as possible, then do the division afterwards, help retain as much precision as possible. – Ricky Mo Oct 05 '21 at 04:21

0 Answers0