0

I don't understand why 500 * (1 - 80/100) results in 99.99999999999997 instead of 100. Where does that come from?

const storage = {
  rawDataVolumeAtGoLive: 500,
  compressionRate: 80,
}

function getCompressedVolumeAtGoLive(storage) {
  if (storage.rawDataVolumeAtGoLive && storage.compressionRate !== null) {
    console.log('storage.rawDataVolumeAtGoLive', storage.rawDataVolumeAtGoLive);
    console.log('storage.compressionRate', storage.compressionRate);
    return storage.rawDataVolumeAtGoLive * (1 - storage.compressionRate / 100);
  }
  return 0;
}

console.log(getCompressedVolumeAtGoLive(storage));
LazioTibijczyk
  • 1,701
  • 21
  • 48
  • a little thing called floating point error – TorNato May 16 '22 at 10:35
  • In addition to the question this was duped as, see also [this question](https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript). – Etheryte May 16 '22 at 10:37

0 Answers0