In this article, you will learn how to round off numbers in Python.

Let’s say you have a float variable with value 123.45

# Import the math library
import math

a = 123.45


In order to round off numbers, you can use the math.ceil() method or math.floor() method. In this example, you will be rounding up and down the float variable ‘a’.

# Import the math library
import math

a = 123.45

# Round up a number to its nearest integer
print(math.ceil(a))
# => 124

# Round down a number to its nearest integer
print(math.floor(a))
# => 123


Note: The math.ceil() method functions by rounding up a number to its nearest integer. The math.floor() method functions by rounding down a number to its nearest integer.
{"ft_lang_label":"__label__en","ft_lang_prob":0.77664435,"math_prob":0.98039144,"size":701,"snap":"2023-40-2023-50","text_gpt3_token_len":179,"char_repetition_ratio":0.12625538,"word_repetition_ratio":0.1983471,"special_character_ratio":0.2767475,"punctuation_ratio":0.12244898,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9993525,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-23T17:46:16Z\",\"WARC-Record-ID\":\"<urn:uuid:8a82b9c6-21cc-4646-b174-285b68279302>\",\"Content-Length\":\"210112\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:369861f6-fe97-4ad4-9df6-993d66ca1bc0>\",\"WARC-Concurrent-To\":\"<urn:uuid:03511d86-5074-4877-a2fa-c597c514fb65>\",\"WARC-IP-Address\":\"104.21.66.113\",\"WARC-Target-URI\":\"https://codesource.io/how-to-round-off-numbers-in-python/\",\"WARC-Payload-Digest\":\"sha1:QYLHKELFMRK72JNRXZFZR4HSBZD5D4V2\",\"WARC-Block-Digest\":\"sha1:6SUHHDPR44OSMUTJYCOKWNJN5R3PRVS4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233506528.19_warc_CC-MAIN-20230923162848-20230923192848-00225.warc.gz\"}"}