You work on TC39, so suggestion: change toString so that any numbers ≥ 2⁵³ or ≤ -2⁵³ are stringified in e-notation, or, alternatively, with the full integer digit expansion and a trailing ".". This makes it clear when precision is limited, without phantom/incorrect digits.
-
-
Replying to @marcan42 @kentaromiura and
I doubt that’s feasible. I bet it would break lots of existing code.
@littledan1 reply 0 retweets 0 likes -
toString always outputs a string which, when parsed as a Number, rounds to the same value. There are multiple strings which would round to the same Number. I think ending it with a bunch of 0's is often more intuitive, which would motivate that choice.
1 reply 0 retweets 1 like -
Replying to @littledan @mathias and
If you'd like to see the fun floating point bits, if you're trying to learn how floats work, you can do that with Number.prototype.toPrecision, toExponential, toFixed, which omit the logic to put 0's at the end.
1 reply 0 retweets 0 likes -
Replying to @littledan @mathias and
My issue is the lack of any evidence that the number is a float; that rounding occurred. JS is in the awkward position of using floats for the use cases of ints. Presumably this drove the decision to have toString output just digits when the float is an exact integer value.
1 reply 0 retweets 0 likes -
Replying to @marcan42 @littledan and
But then toString goes and *rounds* larger ints - at which point they're not floats trying to be ints any more - yet it still outputs just digits. And that is just confusing and messy.
1 reply 0 retweets 0 likes -
Replying to @marcan42 @littledan and
Sure, there are ways to get the full value out. My point here is that the default behavior is unintuitive and misleading in this particular case. Nobody expects an integer to have been rounded. Having to deal with the 53-bit ceiling is bad enough; toString hiding it is worse!
1 reply 0 retweets 1 like -
Unfortunately, the fact that JavaScript Numbers are IEEE 64-bit floats is just something JS devs will have to learn. I don't think toString is hiding anything here--ending in a bunch of zeros implies not as much precision as if it ended in a lot of non-zero digits.
2 replies 0 retweets 1 like -
This Tweet is unavailable.
-
This Tweet is unavailable.
"20" means 16, "30" means 32, 16+20 = 36 which rounds to 32 (step size 8), which then is rounded down for display to 30. And this is why gratuitously rounding numbers for display is a stupid idea. Stuff doesn't make sense.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.