How to Remove All Decimals from Number in Python?

14-Jun-2023

.

Admin

How to Remove All Decimals from Number in Python?

Hi Dev,

In this example, you will learn how to remove all decimals from numbers in python. let’s discuss python removing all decimals from numbers. This tutorial will give you a simple example of how to remove a decimal point from a number in Python. if you want to see an example of how to remove a decimal from a number in Python then you are in the right place. follow bellow step for how to remove decimal places in Python.

There are several ways to remove all decimals from numbers in python. I will give you a simple example to remove a decimal point from a float. we will use the int() and truncate () function to delete all decimal points from the number.

Example 1:


main.py

number1 = 50.560

# Convert float to int

resultNumber = int(number1)

print(resultNumber)

Output:

50

Example 2:

main.py

import math

# Convert float to int

number1 = math.trunc(12.63)

print(number1)

# Convert float to int

number2 = math.trunc(-91.34)

print(number2)

# Convert float to int

number3 = math.trunc(0.45)

print(number3)

Output:

12

-91

0

#Python