String representation of unitful types

julia> typeof(1.0u"kg/m^3") <: Number
true
julia> typeof(1.0u"kg/m^3")
Quantity{Float64, 𝐌  𝐋 ^-3, Unitful.FreeUnits{(kg, m^-3), 𝐌  𝐋 ^-3, nothing}}
julia> Quantity{Float64, 𝐌  𝐋 ^-3, Unitful.FreeUnits{(kg, m^-3), 𝐌  𝐋 ^-3, nothing}} <: Number
ERROR: syntax: missing comma or } in argument list

How can I get a string representation of a unitful type in a such way that it can be parsed back by Julia? For other types it was as simple as string(Symbol(T))

Fyi, your question seems to be related to this open Unitful.jl issue.

1 Like