Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in Python by (2.6k points)
edited by

How can I round off b to 16.75

>>> b
16.749999999999999
>>> round(, 2)
16.749999999999999

I tried round function but it doesn't worked.

2 Answers

0 votes
by (46k points)
edited by

You can use round() :

>>> round(16.749999999999999, 2)
16.75

This works well for all Python versions 2.7 or above. Cheers. 

0 votes
by (106k points)
edited by

For limiting floats to two decimal points you can use the simplest approach which is to use the format() function.

An example is as follows:

a = 13.949999999999999 

format(a, '.2f') 

13.95

The above code will produce a float number as a string rounded to two decimal points.

You can use the following video tutorials to clear all your doubts:-

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...