从IJulia输出中删除科学计数法?

Cry*_*igm 2 julia jupyter-notebook jupyter-lab

如何从Jupyter / IJulia输出中删除科学计数法,而仅获取原始浮点数? 在此处输入图片说明

Cam*_*nek 5

您可以使用标准库中Printf模块中的@printf宏来控制浮点值的打印。此宏将包含格式说明符的字符串作为第一个参数:

julia> using Printf

julia> x = 1.23456e8
1.23456e8

julia> @printf "x is equal to %f .\n" x
x is equal to 123456000.000000 .
Run Code Online (Sandbox Code Playgroud)

在这里,%f格式说明符表示将数字打印为浮点数,默认为小数点右边的6位数字。您可以使用各种标志或子说明符来调整打印输出。如果只希望小数点右边有两位数字,可以%.2f改用:

julia> @printf "x is equal to %.2f .\n" x
x is equal to 123456000.00 .
Run Code Online (Sandbox Code Playgroud)

有关格式说明符的更多信息,请参见此处


Bil*_*ill 5

Formatting 包还可以帮助:

julia> x = 1.23456e8
1.23456e8

julia> using Formatting

julia> format(x)
"123456000"

julia> format(x, commas=true)
"123,456,000"
Run Code Online (Sandbox Code Playgroud)