TDT4109/common/conversion/removeEmptyDecimals.py

15 lines
304 B
Python

def removeEmptyDecimals(n):
"""
Removes .0 from a float if it doesn't add any extra value to the number.
Parameters:
n (float): the value to parse
```
>>> removeEmptyDecimals(2.0)
2
>>> removeEmptyDecimals(2.5)
2.5
```
"""
return int(n) if int(n) == n else n