{"id":24570,"date":"2021-10-22T08:57:49","date_gmt":"2021-10-22T03:27:49","guid":{"rendered":"https:\/\/python-programs.com\/?p=24570"},"modified":"2021-11-05T19:39:07","modified_gmt":"2021-11-05T14:09:07","slug":"python-round-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-round-function-with-examples\/","title":{"rendered":"Python round() Function with Examples"},"content":{"rendered":"

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

The round() function returns a floating-point number with the specified number of decimals that is a rounded version of the specified number.<\/p>\n

The function will return the nearest integer if the number of decimals is set to 0.<\/p>\n

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

round(number, digits)<\/pre>\n

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

number:<\/strong> This is required. It is the number that should be rounded.<\/p>\n

digits:<\/strong> This is Optional. When rounding a number, the number of decimals to use(up to how many digits to be rounded after decimal) The default value is 0.<\/p>\n

Return Value:<\/strong><\/p>\n

The function round() returns the<\/p>\n

If digits<\/strong>\u00a0is not provided, the nearest integer to the given number is used; otherwise, the number is rounded off to digits.<\/p>\n

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

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

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

Given number = 10.5678\r\nGiven no of digits = 2<\/pre>\n

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

The rounded value of the given number 10.5678 upto 2 digits =  10.57<\/pre>\n

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

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

Given number = 7.8<\/pre>\n

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

The rounded value of the given number 7.8 = 8<\/pre>\n

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