what is 2f used with moderators?

# Moderators / float

â€śprintâ€ť treats the % as a special character you need to add, so it can know, that when you type â€śfâ€ť, the number (result) that will be printed will be a floating point type, and the â€ś.2â€ť tells your â€śprintâ€ť to print only the first 2 digits after the point.

**mtf**#3

Not quite. It does not print the first two digits after the point, but rather it rounds the float to two digits. The rounding could be up or down, depending whether the third digit is a 5 or more, or less than 5, respectively.

```
>>> from math import pi
>>> PI = pi
>>> print "PI to 5 decimal places %.5f" % PI
PI to 5 decimal places 3.14159
>>> print "PI to 4 decimal places %.4f" % PI
PI to 4 decimal places 3.1416
>>> print "PI to 3 decimal places %.3f" % PI
PI to 3 decimal places 3.142
>>> print "PI to 2 decimal places %.2f" % PI
PI to 2 decimal places 3.14
>>> print "PI to 1 decimal place %.1f" % PI
PI to 1 decimal place 3.1
>>>
```

**system**#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.