A value like 2.500 reads better as 2.5. To remove trailing zeros from a decimal in Python, call normalize() on a Decimal and format the result with :f, so whole numbers don’t turn into scientific notation:
from decimal import Decimal
f"{Decimal('2.500').normalize():f}" # '2.5'
f"{Decimal('500.000').normalize():f}" # '500'
Pantry weights in pounds serve as the sample data here, and each script was run in Command Prompt with Python 3.12.5.
In this tutorial, we’ll cover Decimal.normalize(), the exponent trap, the :g format for floats, a string-based rstrip() approach, and one helper that handles every input type.
Remove trailing zeros from a Decimal with normalize()
normalize() strips the rightmost zeros from a Decimal. Whole numbers, though, come back as 5E+2 and 1.2E+2:
from decimal import Decimal
weights = ["2.500", "19.990", "0.750", "500.000", "120"]
for w in weights:
d = Decimal(w)
print(f"{w:>8} -> normalize(): {str(d.normalize()):<6} with :f -> {d.normalize():f}")
Output:
2.500 -> normalize(): 2.5 with :f -> 2.5
19.990 -> normalize(): 19.99 with :f -> 19.99
0.750 -> normalize(): 0.75 with :f -> 0.75
500.000 -> normalize(): 5E+2 with :f -> 500
120 -> normalize(): 1.2E+2 with :f -> 120

normalize() turns 500.000 into 5E+2; adding the :f format prints 500.The value hasn’t changed, only its exponent. If you need a fixed number of places instead, see rounding numbers to 2 decimal places in Python.
How do you stop normalize() from returning 5E+2?
The decimal docs offer a small recipe that checks to_integral() and quantizes whole numbers to an integer instead of normalizing them:
from decimal import Decimal
def remove_exponent(d):
# recipe from the decimal module FAQ
return d.quantize(Decimal(1)) if d == d.to_integral() else d.normalize()
for w in ["500.000", "120", "-4.50", "0.000"]:
print(f"{w:>8} -> {remove_exponent(Decimal(w))}")
Output:
500.000 -> 500
120 -> 120
-4.50 -> -4.5
0.000 -> 0
I use this when the result must stay a Decimal for later math. For the opposite job, dropping the fraction entirely, read removing decimal numbers in Python.
Remove trailing zeros from a float with the :g format
A float never stores trailing zeros: 19.990 is already 19.99. The one zero you’ll see is in 2.0, and the g format spec drops it:
values = [3.50, 2.0, 19.990, 1500000.0, 0.0000125]
for x in values:
print(f"{x!r:>12} :g -> {x:<12g} :.15g -> {x:.15g}")
Output:
3.5 :g -> 3.5 :.15g -> 3.5
2.0 :g -> 2 :.15g -> 2
19.99 :g -> 19.99 :.15g -> 19.99
1500000.0 :g -> 1.5e+06 :.15g -> 1500000
1.25e-05 :g -> 1.25e-05 :.15g -> 1.25e-05

:g keeps six significant digits, so large values switch to e-notation; :.15g keeps them readable.Use :.15g unless your values are tiny. Why floats print the way they do is covered in floating-point numbers in Python.
Strip trailing zeros from a number string with rstrip()
When the number arrives as text from a CSV or a form, rstrip("0").rstrip(".") works, but only after checking for a decimal point:
def strip_zeros(text):
if "." not in text: # "10" has no decimals to trim
return text
return text.rstrip("0").rstrip(".")
for s in ["12.5000", "8.000", "10", "0.0300", "250"]:
print(f"{s:>8} -> {strip_zeros(s)}")
print("Trap 1:", "10".rstrip("0")) # zeros before the point
print("Trap 2:", format(0.0000125, "f")) # 'f' keeps only 6 places
Output:
12.5000 -> 12.5
8.000 -> 8
10 -> 10
0.0300 -> 0.03
250 -> 250
Trap 1: 1
Trap 2: 0.000013

"10".rstrip("0") returns 1.Also, format(x, "f") keeps six places, so 0.0000125 becomes 0.000013. To parse the cleaned text, see converting a string to a float in Python.
A reusable Python helper for trailing zeros
My go-to version sends any input through Decimal(str(value)), then normalizes and formats with :f.:
from decimal import Decimal
def clean_number(value):
"""Return value as text with no trailing zeros and no exponent."""
d = Decimal(str(value)).normalize()
return f"{d:f}"
order = [("Flour", 2.500, "lb"), ("Rice", Decimal("10.00"), "lb"), ("Saffron", 0.0000125, "kg"),
("Eggs", 12, "count")]
for item, qty, unit in order:
print(f"{item:<10} {clean_number(qty):>10} {unit}")
Output:
Flour 2.5 lb
Rice 10 lb
Saffron 0.0000125 kg
Eggs 12 count

Don’t strip zeros from prices, though: $19.90 should keep two places. For money, follow printing 2 decimal places in Python instead.
Which method should you use?
| Input | Method | Watch out for |
|---|---|---|
Decimal | f"{d.normalize():f}" | Plain normalize() gives 5E+2 |
float | f"{x:.15g}" | Plain :g rounds to 6 digits |
str | rstrip("0").rstrip(".") | Check for . first |
| Mixed | clean_number() | Returns text, not a number |
You might also like these number guides:
- Format decimal places with f-strings
- Get the decimal part of a number in Python
- Convert a float to an int in Python
- Format a number with commas in Python
Frequently asked questions
How do I remove trailing zeros from a decimal in Python?
Use f"{Decimal(value).normalize():f}". It strips the zeros and avoids scientific notation.
Why does normalize() return 5E+2?
For whole numbers it moves zeros into the exponent. Format with :f or quantize with Decimal(1).
Can I remove trailing zeros from a float?
Floats don’t store them. Use f"{x:.15g}" to print 2.0 as 2.
Why does rstrip(“0”) turn 10 into 1?
It strips zeros before the decimal point too. Only call it when the string contains a dot.
Does removing trailing zeros change the value?
No. 2.500 and 2.5 are equal; only the text you print changes.
Where is Decimal.normalize() documented?
See the decimal module docs, whose FAQ has the remove_exponent recipe.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn