Hello Friends,Hey Dev,
Today, python remove all decimals from number is our main topic. I explained simply about how to remove decimal point from a number in python. We will use how to remove decimal from a number in python. This post will give you a simple example of how to remove decimal places in python. Alright, let’s dive into the details.
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()
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...
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?