iliekturtles / uom

Units of measurement -- type-safe zero-cost dimensional analysis
Apache License 2.0
989 stars 89 forks source link

Formatter with automatic prefixes #438

Open sixties opened 11 months ago

sixties commented 11 months ago

Is there a possibilty to display quantities with automatic "human readable" prefixes? Example: 0.1 s -> 100 ms. As a human one typically chooses the prefix such that that there are 1..3 digits displayed before the fractional part. Maybe one could implement this as an additional DisplayStyle.

iliekturtles commented 11 months ago

There isn't any functionality like this currently. I'm not sure if this should be in scope to be directly in uom, so I'll leave the issue open for consideration.

baarkerlounger commented 11 months ago

Additional human readable formatting options might also be useful for time quantities where you might expect to see eg. 2:30 rather than 2.5 mins or similar .

YgorSouza commented 9 months ago

As a human one typically chooses the prefix such that that there are 1..3 digits displayed before the fractional part

This is called Engineering notation. Rust formats the Duration type like this. But it mostly applies to SI units, so I think it would be hard to reasonably implement something like that in this crate, which is far more general.