Skip to content

Support Unitful.jl quantites #94

@nathanrboyer

Description

@nathanrboyer

It would be nice if this worked natively. Probably not too difficult to implement, but I'm not sure how package extensions work.

julia> using Format, Unitful

julia> x = 12345.6u"lbf"
12345.6 lbf

julia> format(x, commas=true, precision=0)
ERROR: MethodError: no method matching format(::Quantity{Float64, 𝐋 𝐌 𝐓^-2, Unitful.FreeUnits{(lbf,), 𝐋 𝐌 𝐓^-2, nothing}}; commas::Bool, precision::Int64)
The function `format` exists, but no method is defined for this combination of argument types.

Workaround:

julia> format(ustrip(x), commas=true, precision=0, suffix=" $(string(unit(x)))")
"12,346 lbf"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions