2 ms·
Floating point values are definitely perfectly representable as strings - worst case, you just output the binary as a string - but what you may refer to is that
by Tainnor 3y ago
Floating point values are definitely perfectly representable as strings - worst case, you just output the binary as a string - but what you may refer to is that many exact fractions can't be represented exactly as floats and/or that floating-point arithmetic doesn't obey "normal" rules of arithmetic (e.g. addition isn't associative).
- IanCal 3y agoI'll clarify, as yes it's possible, but not using the built in conversions from strings to floats. That is, the following is not true for all x: Number(String(x)) == x
- UncleMeat 3y agoNaNs also cause problems here, since it is not equal to itself.
- joshjje 3y agoSometimes a framework will do weird things, like convert it to scientific notation, or round it, or add a ton of zeroes. Like BigDecimal in Java and Decimal in C#. They can sneak up on you.
- Tainnor 3y agoBigDecimals aren't floats, though. They're arbitrary precision rational numbers.