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'
1
  • 1
    x=Decimal('2.85'); format(x,'0.1f') Commented May 26, 2015 at 14:59

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.