Iceey
Iceey

Reputation: 63

Intl.NumberFormat with maximumFractionDigits

I was trying to format a number in Javascript with the Intl.NumberFormat function. I create a new number formatter with the maximumFractionDigits of 20.

var formatter = Intl.NumberFormat(undefined,{maximumFractionDigits:20});

If i format numbers with this formatter the maximum number of fraction digits isn't 20. e.g: formatter.format(1.123456789) result: "1.123456789" Works as expected.

formatter.format(1.123456789123456) result: "1.12345678912346" In this case the number has 15 fraction digits, the formatted string has only 14. I don't understand that result. It's the same result for chrome firefox

Upvotes: 3

Views: 11090

Answers (1)

Kushan
Kushan

Reputation: 10703

JavaScript Numbers are Always 64-bit Floating Point.

The maximum number of decimals is 17, but floating point arithmetic is not always 100% accurate.

Refer this Floating-Point Guide

Upvotes: 1

Related Questions