To express '%.2f' using format() only

Asked 1 years ago, Updated 1 years ago, 111 views

Use the following code as a way to express the entered mistakes up to 2 decimal places.

a = float(input())
print('%.2f' % a)

However, I don't know how to write only the format() function with % without .

a = float(input())
print('{%.2f}'.format(a))

When executing the above code

Traceback (most recent call last):
  File "<pyshell#108>", line 1, in <module>
    print('{%.2f}'.format(a))
KeyError: '%'

This error message has been received.

How can I set various settings like above with format() only without %?

python3.6.2 python

2022-09-22 19:05

1 Answers

print("{0:0.2f}".format(3.14159))

https://wikidocs.net/13


2022-09-22 19:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.