Skip to content

round(n; sigdigits) without explicit units #326

@mcabbott

Description

@mcabbott

While being able to round in a unit-controlled way is neat (and should perhaps be encouraged n the docs), what's the reason to disallow simple rounding? I expected the second of these to work, and if it did, then code with & without units would behave the same:

len = (120//1)u"cm"
round(u"m", len, sigdigits=2)

tim = 3.0000001u"s"
round(tim, sigdigits=3) # ERROR: specify the type of the quantity to convert to when rounding

Edit: for sigdigits in particular, the objection that the rounding depends on your units does not apply, these agree:

tim_ns = tim |> u"ns"
round(ustrip(tim), sigdigits=3) * unit(tim)
round(ustrip(tim_ns), sigdigits=3) * unit(tim_ns)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions