将Float64转换/解析为String

evf*_*qcg 3 julia

如果之前已经回答过,我道歉,到目前为止我找不到它.

那么如何将Float64转换为ASCIIString呢?

我的尝试

julia> parse(5.0)
ERROR: `parse` has no method matching parse(::Float64)

julia> convert(ASCIIString, 5.0)
ERROR: `convert` has no method matching convert(::Type{ASCIIString}, ::Float64)
 in convert at base.jl:13

julia> parsefloat(5.0)
ERROR: `parsefloat` has no method matching parsefloat(::Float64)
Run Code Online (Sandbox Code Playgroud)

朱莉娅版本0.3.7

res*_*chu 7

使用字符串函数:

julia> string(0.5)
"0.5"
Run Code Online (Sandbox Code Playgroud)

编辑:

对于自定义格式化字符串,您可以使用@sprintf宏:

julia> @sprintf("%.2f",0.5)
"0.50"
Run Code Online (Sandbox Code Playgroud)