A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-December/094425.html below:

[Python-Dev] Sort out formatting differences in decimal and float

[Python-Dev] Sort out formatting differences in decimal and floatStefan Krah stefan-usenet at bytereef.org
Sat Dec 5 12:18:47 CET 2009
Hi,

I'm in the process of implementing formatting in my C-decimal module.
Since testing is quite time consuming, I would appreciate a binding
decision on how the following should be formatted:

>>> from decimal import *
>>> format(float(1234), '020,g')
'0,000,000,000,001,234'
>>> format(float(1234), '0=20,g')
'0,000,000,000,001,234'
>>> 
>>> format(Decimal(1234), '020,g')
'0,000,000,000,001,234'
>>> format(Decimal(1234), '0=20,g')
'0000000000000001,234'

>>> format(Decimal('nan'), '020,g')
'                 NaN'
>>> format(Decimal('nan'), '0=20,g')
'00000000000000000NaN'


You can see that float literally follows PEP-3101:

"If the width field is preceded by a zero ('0') character, this enables
 zero-padding.  This is equivalent to an alignment type of '=' and a
 fill character of '0'."


The advantage of decimal is that the user has the option to suppress
commas. The behaviour of float is slightly easier to implement in C.


So the options are:

   a) 020 is always equivalent to 0=20

   b) 020 is not always equivalent to 0=20



Stefan Krah


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4