+2 votes
in Programming Languages by (73.8k points)
How to round up a float number to 2 or 3 decimal places?

E.g.

32.2345675465 -> 32.23

21.3567885 - > 21.357

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

You can use the round() function to truncate decimal places of a float to your desired number.

E.g.

>>> round(32.2345675465,2)
32.23
>>> round(21.3567885,3)
21.357


...