Very quick question.
x = 10
print("value is {:d}".format(x))
returns
value is 10
on the other hand:
x = 10.0
print("value is {:d}".format(x))
returns
ValueError: Unknown format code 'd' for object of type 'float'
Why doesnt this work?
Very quick question.
x = 10
print("value is {:d}".format(x))
returns
value is 10
on the other hand:
x = 10.0
print("value is {:d}".format(x))
returns
ValueError: Unknown format code 'd' for object of type 'float'
Why doesnt this work?
You would use f not d for floats. And then specify the precision width as 0:
>>> print("value is {:.0f}".format(x))
value is 10
From Python docs: 'd' Decimal Integer. Outputs the number in base 10.
It will output the number in base 10, thats why you are getting the ValueError.