How can I remove all decimal places form a float?
a = 100.0
I want that to become 100
I tried str(a).rstrip('.0')
, but it just returned 1
What about converting it to int
?
>>>int(a)
100
Just for the sake of completeness, there are many many ways to remove the decimal part from a string representation of a decimal number, one that I can come up right now is:
s='100.0'
s=s[:s.index('.')]
s
>>>'100'
Perhaps there's another one more simple.
Hope this helps!
If you do not want to convert it to an int you can also split it.
>>> a = 100.25
>>> str(a).split('.')[0]
>>> '100' # result is now a string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With