The motivation is:
Numbers of similar magnitude line up their decimal points
But it appears I have an off-by-one error for when to transition to that other format. So I've changed
to-2 => '+0.000000',
and added some more test cases (which found another bug that I've fixed -- stripping trailing '0's when I shouldn't). Thanks for catching that.-1 => '+0.000000',
At which points to change format are partially a matter of taste. The first three formats have very little room for matters of taste:
(the most likely change would be to change "-5", probably to something a bit closer to zero).-100 => '+1.0e-999', -10 => '+1.00e-99', -5 => '+1.000e-9',
The last three have only slightly more room:
but the middle ground leaves lots of room for trade-offs. In particular, I wanted small integers to line up nicely (I chose -9999..9999 for my definition of "small") and I wanted a +0.0 format so that we can tell near-integers from non-integers for as long as possible. The +0.000000 and +0 formats allow us to delay going to 'e' format for as long as possible.+9 => '+1.000e+9', +99 => '+1.000e99', +99999 => '+1.00e999',
Finally, add in a desire for fewer formats so that numbers are more likely to line up at their (perhaps implied) decimal points, and I'm stuck with what I used above. (:
- tyeIn reply to Re^2: Display floating point numbers in compact, fixed-width format (thanks)
by tye
in thread Display floating point numbers in compact, fixed-width format
by tye
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |