format
2024. 2. 21. 21:40ㆍ파이썬
728x90
문자와 숫자를 출력하고 싶을 때 형식
a=12
print(f"hello {a}")
소수점 2자리까지 표기하기
final_amount=round(bill_per_person,2)
print(f"Each person shoul pay: ${final_amount}")
-> 그러나 반올림하는것이기 때문에 항상 소수점 2자리를 표시하지는 않음
해결책
:
final_amount="{:.2f}".format(bill_per_person)
print(f"Each person should pay: ${final_amount}")728x90
'파이썬' 카테고리의 다른 글
| 리스트에서 특정 원소의 인덱스를 반환하는 함수 (0) | 2024.02.22 |
|---|---|
| [pandas] 데이터 추출 (1) | 2023.11.22 |
| pd.Series() (0) | 2023.11.22 |
| (파이썬) Modules and Packages (0) | 2022.11.30 |
| (파이썬) Dictionaries (0) | 2022.11.30 |