Student Handbook

Student Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

math.floor

Rounds a number down.

Synopsis

import math
math.floor(number)

Description

floor always goes down, towards minus infinity. For negative numbers that differs from int, which goes towards zero.

Parameters

Name Meaning
number An int or a float.

Return value

An int.

Example

import math

print(math.floor(3.7))
print(math.floor(-3.7))
print(int(-3.7))

It prints:

3
-4
-3

Common mistake

import math

print(math.floor("3.7"))

Python stops with:

TypeError: must be real number, not str

floor needs a number. Convert first: math.floor(float("3.7")).

See also

math.ceil, int, round

math.floor in the Python documentation

Last updated 2 weeks ago