a=[0.001,0.003,0.002]
a.sort()
print a
-> [0.001, 0.002, 0.0030000000000000001]
import fpformat
b=fpformat.fix(a[2],6)
print b
-> 0.003000
b=fpformat.sci(a[2],2)
print b
-> 3.00e-003
Monday, 14 January 2008
floating point format in Python
Subscribe to:
Post Comments (Atom)
1 comment:
If reading from files to get variables. such as:
f=open('d:\\a.txt')
a=f.readline()
aa=a.split() # assuming aa[0] is '0.123',aa[1] is '1.0', both of them are string type.
aa0=float(aa[0]) # Do use float() to convert string to a numerical type.
aa1=float(aa[1])
print aa
# you will get : 1.123
Post a Comment