python - Simple way to round floats when printing -
i working on project has take user inputs , calculations.
what aiming print appear as
inform customer saved 0.71 today
not
inform customer saved 0.7105000000000001 today
is there can put same line of code print function have rounded? or have modify each variable.
i can post code if requested.
round() return floating point value number rounded ndigits digits after decimal point. takes first argument number , second argument precision
no = 0.7105000000000001 print round(no, 2)
second solution:
print "%.2f" % 0.7105000000000001