Reputation: 11
Why is my whole number adding two zero's at the end? I want to convert 104184.04 to 104,184.04 but my output is 10,418,404.00
code
print("{:,.2f}".format(int(10418404)))
Upvotes: 0
Views: 223
Reputation: 1845
You are converting the float value to an integer value before passing it to the format function. Effectively the same as this...
>>> float_value = 104184.04
>>> print("{:,.2f}".format(float_value))
104,184.04
>>> int_value = int(float_value)
>>> print("{:,.2f}".format(int_value))
104,184.00
Upvotes: 1