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 - To round down a number to two decimal places, you multiply it by 100, apply the math.floor() function, and divide by 100.
🌐
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 - At the 2nd decimal place is 4, and the number after it is 5. Since this number is greater than or equal to 5, the number 4 is rounded up to 5. Rounding up numbers can be useful for keeping floating numbers within fixed digits.
🌐
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 ...
🌐
TradingCode
tradingcode.net › python › math › round-decimals
How to round decimal places up and down in Python? • TradingCode
The main difference is that we now use the math.floor() function. This function rounds the number parameter multiplied with the factor variable down. Then we divide again with factor to get the right number of decimal places.
Find elsewhere
🌐
Python
docs.python.org › 3 › library › decimal.html
decimal — Decimal fixed-point and floating-point arithmetic
For instance, 1.3 * 1.2 gives 1.56 while 1.30 * 1.20 gives 1.5600. Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem:
🌐
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, ...
🌐
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 ...
🌐
Mimo
mimo.org › glossary › python › round-function
Mimo: The coding platform you need to learn Web Development, Python, and more.
... from decimal import Decimal, ROUND_HALF_UP # Create Decimal objects instead of using floats num = Decimal('2.675') # Use the quantize() method to round to two decimal places with rounding mode ROUND_HALF_UP rounded_num = num.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) print(rounded_num) ...
🌐
Inspector
inspector.dev › home › round up numbers to integer in python – fast tips
Round Up Numbers to Integer in Python - Inspector.dev
June 17, 2025 - Let’s explore two common rounding methods: The math library in Python provides the ceil() and floor() functions to round numbers up and down, respectively, to the nearest integer.
🌐
GeeksforGeeks
geeksforgeeks.org › python › precision-handling-python
Precision Handling in Python - GeeksforGeeks
December 19, 2025 - Explanation: quantize(Decimal('0.00')) formats the number to exactly 2 decimal places. This method lets you control precision at the integer level. It helps when you want to remove decimal places or determine the nearest higher or lower integer.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Round Up/Down Decimals in Python: math.floor, math.ceil | note.nkmk.me
January 15, 2024 - print(math.floor(10.123)) # 10 print(math.floor(-10.123)) # -11 print(math.ceil(10.123)) # 11 print(math.ceil(-10.123)) # -10 print(int(10.123)) # 10 print(int(-10.123)) # -10 · source: round_towards_infinity.py · You can use round() to round half to even. Round numbers with round() and Decimal.quantize() in Python ·
🌐
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 ...
🌐
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 ...