Seems like you need the floor:

import math
math.floor(a * 100)/100.0

# 28.26
Answer from akuiper on Stack Overflow
Top answer
1 of 10
63

Seems like you need the floor:

import math
math.floor(a * 100)/100.0

# 28.26
2 of 10
39

It seems you want truncation, not rounding.

A simple way would be to combine floor division // and regular division /:

>>> a = 28.266
>>> a // 0.01 / 100
28.26

Instead of the regular division you could also multiply (as noted in the comments by cmc):

>>> a // 0.01 * 0.01
28.26

Similarly you could create a function to round down to other more/less decimals. But because floats are inexact numbers, this can lead to inaccuracies.

def round_down(value, decimals):
    factor = 1 / (10 ** decimals)
    return (value // factor) * factor

print(round_down(28.266, 2))
# 28.26

But as said it's not exactly exact:

for i in range(0, 8):
    print(i, round_down(12.33333, i))
0 12.0
1 12.3
2 12.33
3 12.333
4 12.333300000000001 # weird, but almost correct
5 12.33332           # wrong
6 12.33333
7 12.33333

There are other (more precise) approaches though:

A solution using the fraction module

A fraction can represent a decimal number much more exact than a float. Then one can use the "multiply, then floor, then divide" approach mentioned by Psidom but with significantly higher precision:

import fractions
import math

a = 28.266

def round_down(value, decimals):
    factor = 10 ** decimals
    f = fractions.Fraction(value)
    return fractions.Fraction(math.floor(f * factor),  factor)

print(round_down(28.266, 2))
# 1413/50  <- that's 28.26

And using the test I did with the floats:

for i in range(0, 8):
    print(i, round_down(12.33333, i))
0 12
1 123/10
2 1233/100
3 12333/1000
4 123333/10000
5 1233333/100000
6 1233333/100000
7 1233333/100000

However creating a Fraction will not magically fix an inexact float, so typically one should create the Fraction from a string or a "numerator-denominator pair" instead of from float.

A solution using the decimal module

You could also use the decimal module, which offers a variety of rounding modes, including rounding down.

For this demonstration I'm using a context manager to avoid changing the decimal rounding mode globally:

import decimal

def round_down(value, decimals):
    with decimal.localcontext() as ctx:
        d = decimal.Decimal(value)
        ctx.rounding = decimal.ROUND_DOWN
        return round(d, decimals)

print(round_down(28.266, 2))  # 28.26

Which gives more sensible results for the rounding:

for i in range(0, 8):
    print(i, round_down(12.33333, i))
0 12
1 12.3
2 12.33
3 12.333
4 12.3333
5 12.33333
6 12.333330
7 12.3333300

As with Fraction a Decimal should be created from a string to avoid the intermediate inexact float. But different from Fraction the Decimal have limited precision, so for values with lots of significant figures it will also become inexact.

However "rounding down" is just one of the available options. The list of available rounding modes is extensive:

Rounding modes

decimal.ROUND_CEILING Round towards Infinity.

decimal.ROUND_DOWN Round towards zero.

decimal.ROUND_FLOOR Round towards -Infinity.

decimal.ROUND_HALF_DOWN Round to nearest with ties going towards zero.

decimal.ROUND_HALF_EVEN Round to nearest with ties going to nearest even integer.

decimal.ROUND_HALF_UP Round to nearest with ties going away from zero.

decimal.ROUND_UP Round away from zero.

decimal.ROUND_05UP Round away from zero if last digit after rounding towards zero would have been 0 or 5; otherwise round towards zero.

๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-round-to-two-decimal-places
How to Round to 2 Decimal Places in Python | DataCamp
August 8, 2024 - The round() function is Pythonโ€™s built-in function for rounding float point numbers to the specified number of decimal places. You can specify the number of decimal places to round by providing a value in the second argument. The example below prints 34.15.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 3288381 โ€บ how-to-round-to-2-decimal-places-in-python
How to round to 2 decimal places in python | Sololearn: Learn to code for FREE!
In your case, you can use the round() function to round the result of your calculation to 2 decimal places, like this: total_cost = round((price * quantity) * (1 - discount) * (1 + tax), 2) This will give you the total cost with 2 decimal places, ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ decimal.html
decimal โ€” Decimal fixed-point and floating-point arithmetic
Here are a few recipes that serve as utility functions and that demonstrate ways to work with the Decimal class: def moneyfmt(value, places=2, curr='', sep=',', dp='.', pos='', neg='-', trailneg=''): """Convert Decimal to a money formatted string.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ python
Floating point numbers to two decimal places - possible with standard lib? - Python - The freeCodeCamp Forum
August 24, 2022 - Iโ€™m trying to get 2 decimal places of 0s (e.g, 9.00) in the budget app project. I tried using string formatting, but the program expects a floating point number, not a string. Casting it to a float results in a single .0 because thatโ€™s how floating point numbers work in Python - that gets ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-round-down-to-2-decimals-a-float-using-python
How to round down to 2 decimals a float using Python?
Pass input number, 2 (decimal value) as arguments to the round() function to round the input number upto the 2 decimal places.
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ how to round to 2 decimal places in python
How to Round to 2 Decimal Places in Python โ€ข datagy
April 13, 2023 - # Rounding Down to 2 Decimal Places import math value = 1.2155 rounded = math.floor(value * 100) / 100 print(rounded) # Returns: 1.21 ... In the following section, youโ€™ll learn how to represent values to 2 decimal places without changing the ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-get-two-decimal-places-in-python
How to get two decimal places in Python - GeeksforGeeks
July 23, 2025 - The % operator can also be used to get two decimal places in Python. It is a more traditional approach which makes the use of string formatting technique. ... Python math module provides various function that can be used to perform various ...
๐ŸŒ
Quora
quora.com โ€บ How-do-you-truncate-to-2-decimal-places-in-Python
How to truncate to 2 decimal places in Python - Quora
Method 1: Using โ€œ%โ€ operator Syntax: float(โ€œ%.2fโ€%number) Explanation: The number 2 in above syntax represents the number of decimal places you want the value to round off too.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-round-to-2-decimal-places-in-python
How to Round to 2 Decimal Places in Python
August 22, 2022 - For rounded2, the num is rounded up to 2 decimal places. At the 2nd decimal place is 4, and the number after it is 5.
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-40099.html
Get numpy ceil and floor value for nearest two decimals
I'm trying to get ceiling value of the input for two decimals. import numpy as np a = np.array([-1.784, -1.5888, -0.24444, 0.25555, 1.5, 1.75, 2.0]) np.around(a,2)array([-1.78, -1.59, -0.24, 0.26, 1.5 , 1.75, 2. ]) np.ceil(a)array([-1., -1.,...
๐ŸŒ
Real Python
realpython.com โ€บ python-rounding
How to Round Numbers in Python โ€“ Real Python
December 7, 2024 - Python rounds 2.5 to 2 because it follows the round half to even strategy, which rounds to the nearest even number to minimize rounding bias over many calculations. How can you round numbers to a specific number of decimal places in Python?Show/Hide
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-print-2-decimal-places
How to Print Two Decimal Places in Python
December 22, 2025 - It is still incredibly useful, especially if you are working on older Python versions or complex templates. This method separates the string structure from the data, which I find helpful for long-form reports. # Average price of a gallon of gas in California gas_price = 4.859 # Using the format method for 2 decimal places print("The average gas price is ${:.2f} per gallon.".format(gas_price)) # Output: The average gas price is $4.86 per gallon.
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ 6 ways to round floating value to two decimals in python
6 Ways to Round Floating Value to Two Decimals in Python
November 4, 2024 - The built-in Python function round() can round a floating-point number to an integer or to a specified number of decimal places. You can specify the number of decimal places you want and the number you want to round using two different ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-round-floating-value-to-two-decimals-in-python
How to Round Floating Value to Two Decimals in Python - GeeksforGeeks
July 23, 2025 - In Python, we can use the decimal module to round floating-point numbers to a specific number of decimal places with higher precision and control compared to the built-in floating-point arithmetic.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-get-2-decimal-places-in-python
How to Get 2 Decimal Places in Python - Javatpoint
How to Get 2 Decimal Places in Python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
๐ŸŒ
Studytonight
studytonight.com โ€บ python-howtos โ€บ how-to-round-floating-value-to-two-decimals-in-python
How to Round Floating Value to Two Decimals in Python - Studytonight
So to use them for 2 decimal places the number is first multiplied by 100 to shift the decimal point and is then divided by 100 afterward to compensate. #using round fucntion round(2.357, 2) #using math.ceil() and math.floor() import math num ...