0

So, for whatever reason the following simple math equation is behaving oddly

5.1 * 100
> 509.99999999999994

is there a reason this is not resolving to 510?

what needs to be done in javascript in order for it to equal 510?

-- Edit

this post was flagged as a "duplicate" and pointed to a response that does not help a javascript developer, it simply pointed it to a generic math post. My question was "what needs to be done in javascript in order for it to equal 510".

alilland
  • 1,370
  • 1
  • 16
  • 32
  • "*My question was "what needs to be done in javascript in order for it to equal 510".*" this is what the second duplicate explains. – VLAZ Feb 15 '22 at 19:27
  • answer is `Number((5.1 * 100).toFixed(0))` – alilland Feb 15 '22 at 19:44
  • Already part of the top voted answer: "*If you just don’t want to see all those extra decimal places: simply format your result rounded to a fixed number of decimal places when displaying it.*" The second most voted has a sample implementation, too which you'd use as `Number(strip(5.1 * 100))`. Of course you can also alter the implementation of `strip` but it's still showing off the exact same concept. – VLAZ Feb 15 '22 at 19:47

0 Answers0