I would like to truncate a number with only two positions after decimal point and return this number. But when I use the string format as float(" % .2f" % number)
, it returns 1.0 when the given number is like 1.0000. How could I resolve this problem? Thanks a lot.
It seems like my description was not clear enough. Let me take the 1.0005 as an example. I would like to return the number 1.00 with only two positions after the decimal point, rather than a string "1.00". So I choose to use string format to truncate the original number 1.0005 to a string "1.00" which satisfies the requirement of decimal points but it is still a string, I would like to return a number. So I use the float to convert it to a float number, but it seems like float()
in gonna truncate the number to 1.0.