SON#51
SON#51

Rounding in Python

float_number = 123.456789

# 소수점 이하의 2자리까지 출력
formatted_float_two_decimal = "{:.2f}".format(float_number)
print("formatted_float_two_decimal:", formatted_float_two_decimal)

print('=' * 30)

# 지수를 활용한 과학적 표기법으로 출력
formatted_scientific = "{:.4e}".format(float_number)
print("formatted_scientific:", formatted_scientific)

print('=' * 30)

# 10자리 폭을 가지며, 소수점 이하 2자리까지 출력
formatted_fixed_width = "{:10.2f}".format(float_number)
print("formatted_fixed_width:", formatted_fixed_width)

print('=' * 30)

# 소수점 이하 자릿수 제거
formatted_no_decimal = "{:.0f}".format(float_number)
print("formatted_no_decimal:", formatted_no_decimal)

Is it only rounded at the decimal place?

If integers are also expressed simply, will they be rounded?

Comment
No comment