Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert/Parse Float64 into String

Tags:

julia

I apologize if this has been answered before, I couldn't find it so far.

So how can Float64 be converted into ASCIIString?

My attempts

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)

Julia version 0.3.7

like image 958
evfwcqcg Avatar asked Feb 10 '23 07:02

evfwcqcg


1 Answers

Use the string function:

julia> string(0.5)
"0.5"

EDIT:

For custom formatted strings, you can use the @sprintf macro:

julia> @sprintf("%.2f",0.5)
"0.50"
like image 145
reschu Avatar answered Feb 15 '23 10:02

reschu