Guidelines

format() ν•¨μˆ˜λ‘œ 뢀동 μ†Œμˆ˜μ  숫자 닀루기

μ†Œμˆ˜μ μ„ ν¬ν•¨ν•œ μ‹€μˆ˜ν˜• 데이터λ₯Ό 좜λ ₯ν•  λ•ŒλŠ” {:f}λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

μ€‘κ΄„ν˜Έ μ•ˆμ˜ fλŠ” μ‹€μˆ˜ν˜• 데이터λ₯Ό 좜λ ₯ν•  λ•Œ μ‚¬μš©ν•˜λŠ” 포맷 문자둜 float(λΆ€λ™μ†Œμˆ˜μ )의 μ•½μžμž…λ‹ˆλ‹€.

ν”„λ‘œκ·Έλž˜λ°μ—μ„œ λΆ€λ™μ†Œμˆ˜μ μ€ μ†Œμˆ˜μ μ˜ μœ„μΉ˜κ°€ κ³ μ •λ˜μ–΄ μžˆμ§€ μ•Šμ€ μ‹€μˆ˜λ₯Ό μ˜λ―Έν•©λ‹ˆλ‹€.


: 였λ₯Έμͺ½μ— .숫자λ₯Ό μ‚¬μš©ν•˜λ©΄ μ†Œμˆ˜μ  μ΄ν•˜ 자릿수λ₯Ό 지정할 수 μžˆμŠ΅λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄ {:.2f}λŠ” 주어진 μ‹€μˆ˜μ˜ μ†Œμˆ˜μ  μ΄ν•˜ 두 μžλ¦¬κΉŒμ§€λ§Œ 좜λ ₯ν•©λ‹ˆλ‹€.

μ‹€μˆ˜ν˜• 좜λ ₯ formatting μ˜ˆμ‹œ
float_number = 123.4567 formatted_float = "float_number: {:.2f}".format(float_number) print(formatted_float) # "float_number: 123.46"

과학적 ν‘œκΈ°λ²•μœΌλ‘œ 좜λ ₯ν•˜κΈ°

{:e}λ₯Ό μ‚¬μš©ν•˜λ©΄ μ‹€μˆ˜ν˜• 데이터λ₯Ό μ§€μˆ˜λ₯Ό ν™œμš©ν•œ 과학적 ν‘œκΈ°λ²•(Scientific notation)으둜 좜λ ₯ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄, 123.456789λ₯Ό μ§€μˆ˜ ν‘œκΈ°λ²•μœΌλ‘œ 좜λ ₯ν•˜λ©΄ 1.23e+02κ°€ λ©λ‹ˆλ‹€.

과학적 ν‘œκΈ°λ²• μ˜ˆμ‹œ
float_number = 123.456789 scientific_formatted = "{:.2e}".format(float_number) print(scientific_formatted) # "1.23e+02"

μ†Œμˆ˜μ  μ΄ν•˜ 자릿수 μ œκ±°ν•˜κΈ°

뢀동 μ†Œμˆ˜μ  숫자의 μ†Œμˆ˜μ  μ΄ν•˜ 자릿수λ₯Ό μ œκ±°ν•˜λ €λ©΄ :.0fλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

의미 μ—†λŠ” μ†Œμˆ˜μ  μ œκ±°ν•˜κΈ°
number = 123.0 formatted_number = "{:.0f}".format(number) # μ†Œμˆ˜μ  μ΄ν•˜λ₯Ό ν‘œμ‹œν•˜μ§€ μ•ŠμŒ print(formatted_number) # "123"
Mission
0 / 1

float_numberλ₯Ό μ†Œμˆ˜μ  μ΄ν•˜ 3μžλ¦¬κΉŒμ§€ 좜λ ₯ν•˜λ €λ©΄, 좜λ ₯ ν˜•μ‹μ„ μ–΄λ–»κ²Œ 지정해야 ν• κΉŒμš”?

float_number = 123.456789

formatted_float = "
".format(float_number)

print(formatted_float)

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result