Search code examples
pythonstripping

Python 3 Removing All Decimal numbers from float but keep decimal


I wanted to create numbered bullet points.

Decided the way I wanted to do it was

Strip a float of all numbers behind the decimal, but keep the decimal.

Example: 2.0 would be 2. 3.14 would be 3.

Is there way to do it this way? If so what would it look like?

Once again, Thanks in advance.


Solution

  • str(int(x)) + "."
    

    Converting back to float would add a zero after the decimal, so it has to be left in string.