0

In an Angular app, I'm showing a value in "l/h" unit, but I do a conversion to store this value in "kg/s" in my database. For example, if the user enters 30 l/h, I store 30 / 0.9506 / 3600 = 0.008766393155200223

Then, when the user refreshes the page, the value displayed is not 30 but 29.999999999999993 (the result of 0.008766393155200223 * 0.9506 * 3600).

How could I avoid this conversion side-effect?

jcmag
  • 239
  • 1
  • 3
  • 14

1 Answers1

1

As JavaScript can't handle correctly floating points, in our Angular app we have been using the 'big.js' library to deal with the the decimal operations.

Installation:

npm install big.js
npm install @types/big.js

Import:

import Big from 'big.js';
Javi
  • 345
  • 3
  • 7