4 ms·
It is possible, and most reasonable format systems guarantee it. Javascript guarantees that parseFloat(x.toString()) === x for any fp number x. The same extends
by tlb 8y ago
It is possible, and most reasonable format systems guarantee it. Javascript guarantees that parseFloat(x.toString()) === x for any fp number x. The same extends to JSON formatting. Python guarantees that eval(str(x)) == x.
- jancsika 8y agoThat's because Javascript doesn't print out the shortest possible output. OP's requirement is that the output for 0.1 + 0.11 is displayed as 0.21, and that the output survives a round-trip. Your example satisfies the latter but not the former.