Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncate all numbers after decimal

Tags:

python

decimal

How do you truncate all numbers after a decimal in Python 3?

For example truncate 3.444 to be just 3.

like image 940
Fluxcapacitor Avatar asked Jan 26 '13 16:01

Fluxcapacitor


People also ask

How do I truncate numbers after a decimal in Excel?

Round a number down by using the ROUNDDOWN function. It works just the same as ROUND, except that it always rounds a number down. For example, if you want to round down 3.14159 to three decimal places: =ROUNDDOWN(3.14159,3) which equals 3.141.

How do you limit the numbers after a decimal point?

Using DecimalFormat ##" . This means it limits the decimal place up to 2 digits.


2 Answers

By converting it to an int:

>>> num = 3.444
>>> int(num)
3
like image 145
Martijn Pieters Avatar answered Oct 07 '22 22:10

Martijn Pieters


>>> import math
>>> num = 3.4444
>>> math.trunc(num)
3
like image 42
Quoly Avatar answered Oct 08 '22 00:10

Quoly