Tuesday, 15 April 2014

How do remove trailing numbers in python -



How do remove trailing numbers in python -

this question has reply here:

limiting floats 2 decimal points 14 answers

i working on python project , problem.

i have loop makes list numbers. problem when print out list check if numbers correct.

some of more simpler calculations are: 2.6 * 3 , 1.3 * 9

if check calculator should 7.8 , 11.7, 7.800000000000001 , 11.700000000000001

which not big problem, don't how looks. (first world problem, know)

is there way prepare it?

use string format?

print "%.2f" % (2.6 * 3)

the %.2f means print float 2dp

python

No comments:

Post a Comment