in reply to Re: Display floating point numbers in compact, fixed-width format
in thread Display floating point numbers in compact, fixed-width format

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

-2 => '+0.000000',
to
-1 => '+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.

At which points to change format are partially a matter of taste. The first three formats have very little room for matters of taste:

-100 => '+1.0e-999', -10 => '+1.00e-99', -5 => '+1.000e-9',
(the most likely change would be to change "-5", probably to something a bit closer to zero).

The last three have only slightly more room:

+9 => '+1.000e+9', +99 => '+1.000e99', +99999 => '+1.00e999',
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.

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. (:

                - tye