Search code examples
javascriptcurrency

Calculating prices in JavaScript


I have some energy readings that are fractional numbers like: 167512562.211221.

I need to convert these numbers into an invoice price using a kWh price value.

But Number in JavaScript is floating point and unsuitable for monetary calculations.

How should I do this?


Solution

  • Use a library.

    There are many and this page will help you along with the things you need to know about working with money in JavasScript.

    https://frontstuff.io/how-to-handle-monetary-values-in-javascript