+ 2

How do I convert a number to 2 decimal place in Python

25th May 2023, 10:25 PM
Kayode Ojoawo
Kayode Ojoawo - avatar
1 Resposta
+ 1
You can just simply using the round() function.. However, it rounds up to the n number, where n is a specific interger(meaning that it checks whether the number next to it is greater than 5.. if yes, it then increase n by one then remove all number after it, if not then it keeps the n and remove all number that comes after it.) For example: Var = 3.56789 print(round(Var,2)) #outputs 3.57 instead of 3.56
26th May 2023, 4:47 PM
Dragon RB
Dragon RB - avatar