ปลั๊กอินสำหรับไพธอนวิ่งไป 1 ทศนิยม

รหัสตัวอย่าง

17
0

N

>>> x = 13.949999999999999999
>>> x
13.95
>>> g = float("{0:.2f}".format(x))
>>> g
13.95
>>> x == g
True
>>> h = round(x, 2)
>>> h
13.95
>>> x == h
True
5
0

N

>>> round(1.4756,2)
1.48
>>> round(1.3333,2)
1.33
3
0

N

a_list = [1.234, 2.345, 3.45, 1.45]
round_to_whole = [round(num) for num in a_list]

print(round_to_whole)
3
0

N

answer = str(round(answer, 2))
2
0

N

>>> "{0:0.1f}".format(45.34531)
'45.3'
0
0

N

format(1.4000,'.2f') #to include zeroes while rounding to 2 decimals

หน้าคล้ายกัน

คล้ายกันหน้ากับตัวอย่าง

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังหน้ากับตัวอย่างอยู่ในหมวดหมู่