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.
Discussions

python - 2 decimal places when using math floor - Stack Overflow
You can use the {:.2f} format formatting to display a number with two decimal places. ... import math result = math.floor(1.4) formatted_result = "{:.2f}".format(result) print(formatted_result) #1.00 More on stackoverflow.com
๐ŸŒ stackoverflow.com
rounding - How to round to 2 decimals with Python? - Stack Overflow
@jackz314 6.5 years (and many Python versions) after I wrote this answer, I forget why I thought the zero to be worth including. 2020-07-25T06:44:20.52Z+00:00 ... Most answers suggested round or format. round sometimes rounds up, and in my case I needed the value of my variable to be rounded down and not just displayed as such. ... from math import floor... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to round a whole number to 2 decimal places
https://docs.python.org/3/tutorial/inputoutput.html Depending on what formatting style you prefer, itโ€™s going to look something like: number = 56 print(fโ€{number:.2f}โ€) More on reddit.com
๐ŸŒ r/learnpython
3
3
May 24, 2021
How do I round a number to one decimal place?
This should do it float f = 12.365381f; f = Mathf.Round(f * 10.0f) * 0.1f; You're multiplying it by 10 which would make f =123.65381 Then rounding it which would make f = 124. Then multiplying it by 0.1 to undo the first multiplication which puts the decimal back so f = 12.4 More on reddit.com
๐ŸŒ r/unity
2
8
December 10, 2020
๐ŸŒ
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 ...
๐ŸŒ
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:
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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, ...
๐ŸŒ
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 ...
๐ŸŒ
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?
August 29, 2023 - Pass input number, 2 (decimal value) as arguments to the round() function to round the input number upto the 2 decimal places.
๐ŸŒ
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) ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
Real Python
realpython.com โ€บ python-rounding
How to Round Numbers in Python โ€“ Real Python
December 7, 2024 - To implement the rounding half up strategy in Python, you start as usual by shifting the decimal point to the right by the desired number of places. At this point, though, you need a way to determine if the digit just after the shifted decimal point is less than or greater than or equal to 5. One way to do this is to add 0.5 to the shifted value and then round down with math.floor().
๐ŸŒ
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
January 21, 2021 - 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 ...