+1 vote
ago in Programming Languages by (8.5k 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

0 votes
ago by (16.7k points)

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

...