hi there! can somebody explain the round() function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

hi there! can somebody explain the round() function?

e.g : x = round(1.356, 2) print(×)

14th Nov 2018, 7:18 PM
rita pino
rita pino - avatar
5 Answers
+ 3
The optional second argument in the round function is for precision after the decimal point. So round(1.356, 2) rounds 1.356 to 2 decimal places. That would be 1.36, as among the numbers that have two digits after decimal, it is the closest one to 1.356. Btw Rhyr Core, unfortunately you chose a bad example. Python uses the "round half to even" convention, which means 2.5 is rounded down to 2, even though 3.5 is rounded up to 4.
15th Nov 2018, 4:32 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Say you owe a grocery store owner 129.75 pesos, but you don't have any centavos to pay the exact change. So you round it and pay them 130 pesos instead.
15th Nov 2018, 3:25 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
The round() method rounds a number to the nearest integer. Note: 2.49 will be rounded down (2), and 2.5 will be rounded up (3)
14th Nov 2018, 9:28 PM
Rhyr Core
Rhyr Core - avatar
+ 1
thanks for share
14th Nov 2018, 9:54 PM
rita pino
rita pino - avatar
0
in the real live how can a aplicate it??
14th Nov 2018, 10:18 PM
rita pino
rita pino - avatar