ItSolutionStuff.com

Python Remove All Decimals from Number Example

By Hardik Savani • October 30, 2023
Python

Hello Friends,

Today, python remove all decimals from number is our main topic. we will help you to give an example of how to remove decimal point from a number in python. If you have a question about how to remove decimal from a number in python then I will give a simple example with a solution. If you have a question about how to remove decimal places in python then I will give a simple example with a solution.

There are several ways to remove all decimals from number in python. i will give you simple one example to remove decimal point from a float. we will use int() and trunc() function to delete all decimal point from number.

Example 1:

main.py

number1 = 45.560
  
# Convert float to int
resultNumber = int(number1)
  
print(resultNumber)

Output:

45

Example 2:

main.py

import math
  
# Convert float to int
number1 = math.trunc(120.63)
print(number1)
  
# Convert float to int
number2 = math.trunc(-90.34)
print(number2)
  
# Convert float to int
number3 = math.trunc(0.45)
print(number3)

Output:

120
-90
0

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Python Format Number to 2 Decimal Places Example

Read Now →

How to Sort List Descending in Python?

Read Now →

How to Generate Random Float Numbers in Python?

Read Now →

Python Generate Random Number Between 0 to 1 Example

Read Now →

Python Generate Random Number Between 1 and 10 Example

Read Now →

Python Generate List of Random Float Numbers Example

Read Now →

Python Generate List of Unique Random Numbers Example

Read Now →

Python Count Number of Specific Words in String Example

Read Now →

Python String Convert to Lowercase Example

Read Now →

How to Count Number of Elements in a List in Python?

Read Now →

How to Get the Last Element of a List in Python?

Read Now →

Python List Remove Element by Value Example

Read Now →

Python Delete Files with Specific Extension Example

Read Now →

Python Post Request with Bearer Token Example

Read Now →

How to Add Seconds to DateTime in Python?

Read Now →