• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Floor in Python – Find Floor of Number with math.floor() Function

Floor in Python – Find Floor of Number with math.floor() Function

February 7, 2022 Leave a Comment

To find the floor of a number in Python, we can use the Python floor() function from the math module. The math.floor() Python function rounds a number down to the nearest integer.

import math 

floor_of_5p2 = math.floor(5.2)

print(floor_of_5p2)

#Output:
5

The Python math module has many powerful functions which make performing certain calculations in Python very easy.

One such calculation which is very easy to perform in Python is finding the floor of a number.

We can find the floor of a number easily with the Python math module floor() function.

Below are some examples of how to use math.floor() in Python to round down and find the floor of numbers.

import math 

print(math.floor(5.2))
print(math.floor(10.8))
print(math.floor(43.5))
print(math.floor(-12.3))
print(math.floor(-0.3))

#Output:
5.0
10.0
43.0
-13.0
-1.0

If you want to round up and get the ceiling of a number in Python, you can use the math.ceil() Python function. To round to the nearest integer, you can use the Python round() function.

If you are using pandas in Python you can find the ceiling of a column or Dataframe with the pandas floor() function.

Hopefully this article has been beneficial for you to learn how to get the floor in Python of a number with the math.floor() function.

Other Articles You'll Also Like:

  • 1.  Python cube root – Find Cube Root of Number With math.pow() Function
  • 2.  Using Python to Split String by Newline
  • 3.  pandas min – Find Minimum Value of Series or DataFrame
  • 4.  Read Last Line of File Using Python
  • 5.  Check if List is Subset of Another List in Python
  • 6.  Python math.factorial() function – Calculate Factorial of Number
  • 7.  Get Length of File Using Python
  • 8.  Get Days in Month from Date in pandas DataFrame
  • 9.  How to Subtract Two Numbers in Python
  • 10.  Get Week Number from Date in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy

x