Contribution: nice floating point number formatting

Carel Fellinger cfelling at iae.nl
Sun Oct 31 11:41:26 EST 1999


William Park <parkw at better.net> wrote:
> On Sat, Oct 30, 1999 at 01:00:06AM +0000, David S. Harrison wrote:
>> # Returns a nicely formatted string for the floating point number
>> # provided.  This number will be rounded to the supplied accuracy
>> # and commas and spaces will be added.  I think every language should
>> # do this for numbers.  Why don't they?  Here are some examples:
>> # >>> print niceNum(123567.0, 1000)
>> # 124,000
>> # >>> print niceNum(5.3918e-07, 1e-10)
>> # 0.000 000 539 2
>> # This kind of thing is wonderful for producing tables for
>> # human consumption.

> It may be good for human eye, but it creates havoc when piped to another
> program.

Besides, in true human languages (like Dutch:) the use of point and comma is
interchanged. Better have an option for that then, or even better obey locale.

And for the spaces in the decimal part, are you shure that is conventional?
I can't remember having seen this *ever* in my life. At least not in my life
as a programmer.

-- 
groetjes, carel




More information about the Python-list mailing list