trunc function - python math module

trunc function of python math module returns only the integer portion of the number

Math Updated 25 Sep 2016 1 min read

Method Name

trunc(aNumber_in)

Method Overview

The trunc function of the python math module returns only the integer part of a floating
point number.

Example

python
# Get only integer portion of Silver Ratio

SilverRatio     = 2.4142135623

IntPart1         = math.trunc(SilverRatio)

print("Truncation of  Silver Ratio resulted in: {}".format(IntPart1))

# Truncate Gelfond's constant

GelfondsConstant  = 23.1406926327

IntPart2      = math.trunc(GelfondsConstant)

print("Truncation of  Gelfonds Constant in: {}".format(IntPart2))

Output

Output
Truncation of  Silver Ratio resulted in: 2

Truncation of  Gelfonds Constant in: 23