You can use the normalize method to remove extra precision.

>>> print decimal.Decimal('5.500')
5.500
>>> print decimal.Decimal('5.500').normalize()
5.5

To avoid stripping zeros to the left of the decimal point, you could do this:

def normalize_fraction(d):
    normalized = d.normalize()
    sign, digits, exponent = normalized.as_tuple()
    if exponent > 0:
        return decimal.Decimal((sign, digits + (0,) * exponent, 0))
    else:
        return normalized

Or more compactly, using quantize as suggested by user7116:

def normalize_fraction(d):
    normalized = d.normalize()
    sign, digit, exponent = normalized.as_tuple()
    return normalized if exponent <= 0 else normalized.quantize(1)

You could also use to_integral() as shown here but I think using as_tuple this way is more self-documenting.

I tested these both against a few cases; please leave a comment if you find something that doesn't work.

>>> normalize_fraction(decimal.Decimal('55.5'))
Decimal('55.5')
>>> normalize_fraction(decimal.Decimal('55.500'))
Decimal('55.5')
>>> normalize_fraction(decimal.Decimal('55500'))
Decimal('55500')
>>> normalize_fraction(decimal.Decimal('555E2'))
Decimal('55500')
Answer from senderle on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to terminate or remove the .0 point from an int.
r/learnpython on Reddit: How to terminate or remove the .0 point from an int.
December 9, 2022 -

Hello everyone,

I am still new to python and learning.

So I practiced some exercises and made an app that calculates the percentage from the number the user enters.

My question use, how can I terminate the .0 part if the user enters an Int and keep the decimal part if they enter a float?

so for example, 5% of 100 is 5 ( Int)

and 5.1% of 100 is 5.1 (float)

๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to format floats without trailing zeros?
How to Format Floats Without Trailing Zeros? - AskPython
May 12, 2023 - Python offers four effective methods to remove trailing zeros from float values: the to_integral() and normalize() functions, the str() and rstrip() functions, a while loop, and the float() function.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to eliminate trailing zeros?
r/learnpython on Reddit: How to eliminate trailing zeros?
February 12, 2020 -

I have a float formatted to 2 decimal places. I need to eliminate the 2nd decimal place if it's a "0" but still keep 2 decimal places open for when its 2 whole numbers.

number = float(25.20458)
    print(format(number, ".2f"))
#Comes out as 25.20
#Need 25.2

Windows 10 and Python 3.7

๐ŸŒ
Python Guides
pythonguides.com โ€บ remove-the-trailing-zeros-from-a-decimal-in-python
Remove Trailing Zeros from Decimal in Python
September 3, 2025 - We used str() to convert the variable to a string and then used the .rstrip(0), which stands for the right strip and removes the specified 0 argument from the end of the string. Python provides this simple technique to remove trailing zeros from decimals using the float() function.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-remove-trailing-zeros-from-decimal
How to Remove the trailing Zeros from a Decimal in Python | bobbyhadz
Copied!from decimal import Decimal num = Decimal('1.230000') string = str(num) without_trailing_zeros = string.rstrip( '0').rstrip('.') if '.' in string else string result = Decimal(without_trailing_zeros) print(result) # ๐Ÿ‘‰๏ธ 1.23 ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ decimal.html
decimal โ€” Decimal fixed-point and floating-point arithmetic
This has the same semantics as the unary plus operation, except that if the final result is finite it is reduced to its simplest form, with all trailing zeros removed and its sign preserved. That is, while the coefficient is non-zero and a multiple of ten the coefficient is divided by ten and the exponent is incremented by 1. Otherwise (the coefficient is zero) the exponent is set to 0. In all cases the sign is unchanged. For example, Decimal('32.100') and Decimal('0.321000e+2') both normalize to the equivalent value Decimal('32.1').
Find elsewhere
๐ŸŒ
Kodeclik
kodeclik.com โ€บ remove-trailing-zeros-in-python-string
How to remove Trailing Zeros from a given Python String
July 15, 2025 - To keep the notation simple we reverse the string for use in an iterator and then re-reverse it (using string slicing operators) after the zeros are removed. mystring = "314.50600" inside = False newstring = '' for x in reversed(mystring): if (not(inside) and x=="0"): pass else: newstring = newstring + x inside = True answer = newstring[::-1] print(answer) ... The above code can be made more succinct using Pythonโ€™s string slicing operators in a while loop.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-remove-decimal-in-python
How to Remove Decimal in Python - Javatpoint
How to Remove Decimal in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-remove-all-decimals-from-a-number-using-python
How to remove all decimals from a number using Python? - GeeksforGeeks
March 27, 2025 - Explanation: This code converts floating-point numbers to integers using the int() function, which removes the decimal part. It then prints the converted values and shows the data types of the original and converted numbers using type(). ... ...
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-36498.html
remove zeros at the end of a number
Hello, I am trying to remove the .0000 in the result of my window for variable carres and cubes. I tried truncate, int, round but nothing helps. from tkinter import * import math def afficher(): nbs = range(20,41) for n in nbs: car...
๐ŸŒ
AlgoMonster
algo.monster โ€บ liteproblems โ€บ 2710
2710. Remove Trailing Zeros From a String - In-Depth Explanation
In-depth solution and explanation for LeetCode 2710. Remove Trailing Zeros From a String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
๐ŸŒ
Python Help
pythonhelp.org โ€บ tutorials โ€บ get-rid-of-0
How to get rid of that pesky .0 in Python
The round() function in Python can be used to round off a float value to a specified number of decimal places. We can use this function to remove the โ€œ.0โ€ from a float value by rounding it to zero decimal places.