10.0
and 10
are the same float
value. When you print
that value, you get the string 10.0
, because that's the default string representation of the value. (The same string you get by calling str(10.0)
.)
If you want a non-default representation, you need to ask for it explicitly. For example, using the format
function:
print format(rounded_value, '.0f')
Or, using the other formatting methods:
print '{:.0f}'.format(rounded_value)
print '%.0f' % (rounded_value,)
The full details for why you want '.0f'
are described in the Format Specification Mini-Language, but intuitively: the f
means you want fixed-point format (like 10.0
instead of, say, 1.0E2
), and the .0
means you want no digits after the decimal point (like 10
instead of 10.0
).
Meanwhile, if the only reason you round
ed the value was for formatting… never do that. Leave the precision on the float, then trim it down in the formatting:
print format(value, '.0f')