{"id":24198,"date":"2021-10-14T09:17:05","date_gmt":"2021-10-14T03:47:05","guid":{"rendered":"https:\/\/python-programs.com\/?p=24198"},"modified":"2021-11-05T20:56:16","modified_gmt":"2021-11-05T15:26:16","slug":"python-program-for-trunc-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-trunc-function\/","title":{"rendered":"Python Program for trunc() Function"},"content":{"rendered":"

In the previous article, we have discussed Python Program for ldexp() Function<\/a>
\ntrunc() Function in Python:<\/strong><\/p>\n

The math.trunc() method returns the integer part of a number that has been truncated.<\/p>\n

Note:<\/strong> Please keep in mind that this method will NOT round the number up or down to the nearest integer, but will simply remove the decimals.<\/p>\n

Syntax:<\/strong><\/p>\n

math.trunc(x)<\/pre>\n

Parameters:<\/strong><\/p>\n

x:<\/strong> This is required. It is a number. The number from which you want to remove the decimal point(truncate). If the value is not a number, a TypeError is returned.<\/p>\n

Return Value:<\/strong> Returns an int value that represents a number’s truncated integer parts.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first number = 870.26\r\nGiven second number = -11.56<\/pre>\n

Output:<\/strong><\/p>\n

The truncated value of the given first number  870.26  =  870\r\nThe truncated value of the given second number  -11.56  =  -11<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first number = 80.432\r\nGiven second number = 22.4<\/pre>\n

Output:<\/strong><\/p>\n

The truncated value of the given first number  80.432  =  80\r\nThe truncated value of the given second number  22.4  =  22<\/pre>\n

Program for trunc() Function in Python<\/h2>\n