Google App Script Floating Precision Error
19:05 05 May 2026

I noticed an issue with GAS when dealing with certain floats. I have a function that rounds floats to the nearest hundredths place, which is just the single line:

(Math.round(num * 100) / 100);

The problem arises with certain values. For example, if I set const num = 8924.621 in GAS, it automatically resolves to 8924.620999999999 Or if I set const num = 8924.72 it resolves to 8924.719999999999

The value was originally being taken from an HTML form using document.getElementById("num").value I originally thought it was an issue with how HTML was resolving the input but I later realized that it was GAS doing this. I cannot replicate this error in my IDE or within Mozilla's Javascript sandbox. If I add .toFixed(2) it changes the number to a string making comparisons difficult without converting them back to a float, however doing this reintroduces the floating point error.

javascript google-apps-script precision