Message151790
| Author |
py.user |
| Recipients |
py.user |
| Date |
2012年01月22日.22:25:29 |
| SpamBayes Score |
0.0047156066 |
| Marked as misclassified |
No |
| Message-id |
<1327271130.3.0.873784301126.issue13838@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
http://docs.python.org/py3k/library/string.html#format-specification-mini-language
The '#' option:
"For floats, complex and Decimal the alternate form causes the result of the conversion to always contain a decimal-point character, even if no digits follow it. Normally, a decimal-point character appears in the result of these conversions only if a digit follows it. In addition, for 'g' and 'G' conversions, trailing zeros are not removed from the result."
1)
>>> import decimal
>>> '{0:#.5g}'.format(1.5)
'1.5000'
>>> '{0:.5f}'.format(decimal.Decimal(1.5))
'1.50000'
>>> '{0:.5g}'.format(decimal.Decimal(1.5))
'1.5'
>>> '{0:#.5g}'.format(decimal.Decimal(1.5))
'1.5'
>>>
no zeros with "#"
2)
>>> import decimal
>>> '{0:#.5g}'.format(decimal.Decimal('1.500000000000'))
'1.5000'
>>> '{0:.5g}'.format(decimal.Decimal('1.500000000000'))
'1.5000'
>>>
zeros without "#" |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年01月22日 22:25:30 | py.user | set | recipients:
+ py.user |
| 2012年01月22日 22:25:30 | py.user | set | messageid: <1327271130.3.0.873784301126.issue13838@psf.upfronthosting.co.za> |
| 2012年01月22日 22:25:29 | py.user | link | issue13838 messages |
| 2012年01月22日 22:25:29 | py.user | create |
|