Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python – Remove Decimal Values – trunc() Function with Examples

trunc() function is a mathematical function which is use to remove the decimal values from specified expression and return the integer value.

trunc() Function in Python

trunc() function exists in Standard math Library of Python Programming Language. The purpose of this function is to return a value which does not have decimal part but the integer value.

 

Syntax

The syntax of trunc() function in python is:
math.trunc ( x )

 

Parameters

x is any valid Python number (positive or negative).
Note: if the x parameter is not a number, trunc() function will return an error.

 

Return Value

This function will return a real value x truncated to an Integral which is most likely an integer.

 

Python trunc() Function Example


Output of Python trunc() Function
15
-2
3
286
5
1

Note that in output all the numbers whether they are negative or positive have decimal are going to be truncate by using trunc() function. But if argument is not a number than trunc() function will give a TypeError.

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved