Describes the round () method in Python.
This article mainly introduces the round () method in Python, which is the basic knowledge for getting started with Python. For more information, see
The round () method returns x rounded to n decimal places.
Syntax
The syntax of the round () method is as follows:
?
Parameters
- X -- this is a numeric expression.
- N -- this is also a numerical expression.
Return Value
This method returns x rounded to n digits.
Example
The following example shows how to use the round () method.
?
1 2 3 4 5 |
#! /Usr/bin/python Print "round (80.23456, 2):", round (80.23456, 2) Print "round (100.000056, 3):", round (100.000056, 3) Print "round (-100.000056, 3):", round (-100.000056, 3) |
When we run the above program, it will produce the following results:
?
1 2 3 |
Round (80.23456, 2): 80.23 Round (100.000056, 3): 100.0 Round (-100.000056, 3):-100.0 |