“Tempat desimal Python 2” Kode Jawaban

Format ke 2 atau n tempat desimal Python

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

Tempat desimal Python 2

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

>> 432.45

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

>> 321.00
Wild Weasel

memaksa dua tempat desimal python

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

Menemukan 2 Tempat Desimal Python

a_float = 3.14159
formatted_float = "{:.2f}".format(a_float)
AK-47

format tempat desimal Python 2

>>> 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

desimal di Python

>>> from decimal import *
>>> getcontext().prec = 6
>>> Decimal(1) / Decimal(7)
Decimal('0.142857')
>>> getcontext().prec = 28
>>> Decimal(1) / Decimal(7)
Decimal('0.1428571428571428571428571429')
Dead Dormouse

Jawaban yang mirip dengan “Tempat desimal Python 2”

Pertanyaan yang mirip dengan “Tempat desimal Python 2”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya