I'm designing a new config/data format, which will be in YAML. Many of the inputs are int/float values, with associated units (e.g. liter, quart, pint, second, minute, ...).
I've been searching and reading, but still can't figure out: What is the best way to associate a value and unit to a config item in YAML?
Example: Say I have a list of several beverages, and (among other things), I want to input their volume. I can think of a few ways, but (at least in my opinion) none of them are really ideal:
Require all volume values to be input in the same units.
Forces the user to do the unit conversion him/herself, which is tedious, error-prone, and difficult to verify later, because now the quantity input differs from the original quantity listed for the beverage. (Beverages come from several different sources, each potentially using a different unit of measure.)
Represent the value with a sequence of volume and units. Example:
volume: [ 0.5, Gallons ](A mapping would work as well, although more verbose) The sequence might be OK, but I'm not sure if I'm comfortable with it.
Use two "volume" values, one for value, the other for units. Example:
volume_value: 0.5 volume_units: GallonsI think this is a non-starter. Verbose, very loose association, error-prone.
Use a string instead, and parse it in the application. Example:
volume: 0.5 GallonsSimplest to enter, and is very easy to write a robust parser. Seems perhaps like a bit of a hack, though...
Application tags:
volume: !gallons 0.5Not sure about this one, as I am new to YAML and don't yet have a good understanding of tags. Syntax is a little more fragile, perhaps.
So, the question is: per the YAML spec, or defacto best practice/convention, is there a specific way of representing values + units? Whether it's one of the five I listed or something else, I do hope there is a "right answer", to stay within the site Question guidelines.