2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python3で指数表記を避ける

Posted at

Pythonでfloatを文字列に変換すると、値によっては指数表記になります。それを避けたい場合、書式指定にfを設定します。

print(x)
#=> 1.2345e-06

print(f"{x:f}")
#=> 0.000001

小数点以下の桁数を指定することもできます。

print(f"{x:.15f}")
#=> 0.000001234500000

ここまではf-stringを利用してきましたが、もちろんstr.formatを利用することもできます。

print("{0:f}".format(x))
#=> 0.000001

 print("{0:.15f}".format(x))
0.000001234500000

環境情報

$ python3 -V
Python 3.12.3

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?