JavaScript calculations are inaccurate with decimal numbers with more than 16 digits

Hi Mozilla Community,

I just tried decimal calculations in JavaScript and C# and noticed that the JavaScript calculations are inaccurate for numbers with 17 or more digits. But it is accurate in C#. Take a look at the examples and screenshots for reference. Here’s my question: Is it possible to calculate decimal numbers in JavaScript with the same accuracy as in C#?




Hi Angelin_faith! This is a known issue with floating-point math (math with numbers with a decimal point) in just about every programming language. For more information:

JavaScript does not have the same language features as C# for extended-precision floats or decimal constants. The first site suggests the decimal.js library for arbitrary-precision decimal calculations.