Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the use of the round () function in Python

Shulou Source: shulou.com Published: 2022-06-02 07:11:09 09月30日 Update

This article introduces what is the use of the round () function in Python, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Description

The round () method returns the rounded value of the floating point number x.

Grammar

The following is the syntax of the round () method:

Round (x [, n]) parameter

X-numeric expression.

N-- a numeric expression that represents the number of places from the decimal point.

Return value

Returns the rounded value of the floating point number x.

Example

The following shows an example of using the round () method:

Example #! / usr/bin/pythonprint "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)

The output result of the above instance is as follows:

Round (80.23456, 2): 80.23round (100.000056, 3): 100.0round (- 100.000056, 3):-100.0 about the usefulness of the round () function in Python is shared here. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Examples methods functions rounding content values more points expressions syntax rounding help yes since childhood digits interests parameters boys buddies articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Shulou Tech Info Xiaomi Shulou Information