0

Why does the following code return 0.30000000000000004?

function nfunc(f1, f2) {
  return f1 + f2
}

console.log(nfunc(0.2, 0.1));

> 0.30000000000000004
  • A very similar question has been asked before here: https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript Let me know if that helps. – arjabbar Jun 27 '21 at 19:05
  • Take a look at the below to resolve with decimal issue. https://stackoverflow.com/questions/10473994/javascript-adding-decimal-numbers-issue – Thomson Mixab Jun 27 '21 at 19:09

0 Answers0