“Python 2 Podziałowe miejsca” Kod odpowiedzi

Format do 2 lub N Python

num = 123.4567
formatted_num = '{0:.2f}'.format(num) # to 2 decimal places
# formatted_num = '123.46'
Anxious Alligator

Python 2 miejsca po przecinku

print(format(432.456, ".2f"))

>> 432.45

print(format(321,".2f"))

>> 321.00
Wild Weasel

Wymień dwa miejsca po przecinku Python

print ("{0:.2f}".format(a)) 
Lively Lynx

Drukowanie z formatem zmiennoprzecinkowym do 2 miejsc po przecinku Python

formatted_float = "{:.2f}".format(a_float)
Spotless Seahorse

Python 2 Podziałowe miejsca

>>> foobar = 3.141592
>>> print(f'My number is {foobar:.2f} - look at the nice rounding!')

My number is 3.14 - look at the nice rounding!
Wide-eyed Wren

Python 2 Podziałowe miejsca

print "%.2f" % 5
Wide-eyed Wren

Odpowiedzi podobne do “Python 2 Podziałowe miejsca”

Pytania podobne do “Python 2 Podziałowe miejsca”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu