Skip to content

Instantly share code, notes, and snippets.

@ugo-nama-kun
Created August 4, 2021 07:12
Show Gist options
  • Save ugo-nama-kun/b79b6498e43de5287eb96516affad882 to your computer and use it in GitHub Desktop.
Save ugo-nama-kun/b79b6498e43de5287eb96516affad882 to your computer and use it in GitHub Desktop.
python の有効数字
print('{:.3f}'.format(123.456))
# 123.456
print(f"{0.12345678:.3f}")
# 0.123
# Other Examples
print('{:.3e}'.format(123.456))
print('{:.3g}'.format(123.456))
print('{:.3}'.format(123.456))
# 1.235e+02
# 123
# 1.23e+02
print('{:.8f}'.format(123.456))
print('{:.8e}'.format(123.456))
print('{:.8g}'.format(123.456))
print('{:.8}'.format(123.456))
# 123.45600000
# 1.23456000e+02
# 123.456
# 123.456
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment