python - How to fix floating point decimal to two places even if number is 2.00000 -
this have:
x = 2.00001
this need:
x = 2.00
i using:
float("%.2f" % x)
but is:
2
how can limit decimal places 2 , make sure there 2 decimal places if zero?
note: not want final output string.
this works:
'%.2f" % float(x)
previously answered this:
how this?
def fmt2decimals(x): s = str(int(x*100)) return s[0:-2] + '.' + s[-2:]
afaik can't trailing zeros format specification %.2f
.
Comments
Post a Comment