%g and fpformat.sci()

Sivakumar Bhaskarapanditha Sivakumar.Bhaskarapanditha at abaqus.com
Thu Jun 30 20:21:46 CEST 2005



How can I control the number of digits after the decimal point using the %g
format specifier. I am not able to get more than 3 digits as shown below.


>>> a = 1.234e-5

>>> '%g' % a


>>> '%.2g' % a


>>> '%.4g' % a


>>> '%.5g' % a


>>> '%.6g' % a


>>> '%.7g' % a


>>> import fpformat

>>> fpformat.sci(a,7)




In the above example there are only 3 digits after decimal. If I set
a=1.234567e-8 I can control part of it but I am trying to find a way of
filling the rest with zeros as given by the fpformat. 


Ofcourse I can use the fpformat or do some checks. But is there any direct
way (I need a something that doesn't affect performance). 


Thanks a bunch for your help.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050630/2785720b/attachment.html>

More information about the Python-list mailing list