Skip to content

Add function for run-time parsing #214

@alhirzel

Description

@alhirzel

The @u_str macro is useful when units are known in advance. In some cases, however, units must be determined at runtime. This requires parsing strings as numeric and Unitful values, which is currently sort of ugly:

val, unit = split(rawValue, " "; limit=2)
return parse(Float64, val)*(@eval @u_str $unit) # ugly

I'd like to propose that Unitful include a function which exposes this kind of behavior (i.e. parse quantity from string). It would be good if it were resilient to having a space (or not) between the numeric and the unit.

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