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 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -