For a float number a.bc without underflow and overflow, does a.bc.toString() always =="a.bc"? May it return something like "a.bc00000000000000000001"?

For a float number a.bc without underflow and overflow, does a.bc.toString() always =="a.bc"? May it return something like "a.bc00000000000000000001"?
javascript
Ethan Jackson

For example, I know 0.12 is not exactly equals to 12/100 in decimal because it needs to be rounded to some value. However, I'm not asking about mathematical problem , but about Javascript spec that string converting without other calculations.

My question is, if someone gives you a float number that without underflow and overflow (eg:from http response or hardcoded value):

const obj={ "val":a.bc; };

,does Javascript spec ensures that obj.val.toString() always return "a.bc"?

Would there be any cases that obj["val"].a.bc.toString() return something like "a.bc00000000000000000001" (actual value of the float value that rounded)?

Answer

Your question isn't totally clear, but if a number can be expressed in JavaScript as a finite number, then it will not suddenly gain a rounding error unless mathematical operations are applied to it.

This is true for numbers parsed from JSON as well.

Related Articles