-1

When I call this function f = new Function("return 2.3*3;") I get 6.8999999999999995 instead of 6.9. How to have the exact result?

asv
  • 3,332
  • 7
  • 24
  • 47

1 Answers1

2

Use toFixed function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

    var num = eval("2.3*3")
console.log(num.toFixed(1))
RICKY KUMAR
  • 643
  • 4
  • 11