Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how do I round a number to two decimal places in python 3 without using .2f?

+1 vote
asked Jun 19 by Matthew Kim (130 points)
The instructors says we can round it, but how do I do that without using .2f? (I'm not supposed to use .2f yet)

2 Answers

0 votes
answered Jun 20 by Peter Minarik (55,660 points)

This article should help. Use the round() function.

x = round(5.76543, 2)
print(x)
commented Jun 27 by Matthew Kim (130 points)
thanks so much!
0 votes
answered Jun 22 by Tegah D Oweh (140 points)
x = 5.85629
print(x)
x = x * 100
x = round(x, 0)
x = x / 100
print(x)
commented Jun 27 by Matthew Kim (130 points)
thanks a lot!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...