Convert a string to integer with decimal in Python

How about this?

>>> s="23.45678"
>>> int(float(s))
23

Or…

>>> int(Decimal(s))
23

Or…

>>> int(s.split('.')[0])
23

I doubt it’s going to get much simpler than that, I’m afraid. Just accept it and move on.

Leave a Comment