9

Is there a format option such that

>>> '%.1(format)'%2.85

gives '2.8'?

In Python 2.7, 'f' format rounds to nearest

>>> "{:.0f}".format(2.85)
'3'
>>> "%.0f"%2.85
'3'
>>> "%.1f"%2.85
'2.9'
>>> "%i"%2.85
'2'
jf328
  • 6,841
  • 10
  • 58
  • 82

1 Answers1

2

No, there is not. Have a look at the documentation for a complete list of supported floating point format specifiers.

You need to round in your code instead

Eric
  • 95,302
  • 53
  • 242
  • 374