I am trying to find a way to automatically format a measurement and unit in a string in technical notation . This is a special case of scientific notation, in which the indicator is always a multiple of three, but is indicated using kilo, mega, milli, micro prefixes.
It will be similar to this post , except that it should handle the entire range of SI units and prefixes.
For example, I get a library that will format such values ββthat: 12345.6789 Hz will be formatted as 12 kHz or 12.346 kHz or 12.34456789 kHz 1234567.89 J will be formatted as 1 MJ or 1.23 MJ or 1.2345 MJ And so on.
The JSR-275 / JScience handles the device measurement in order, but I have not yet found something that will automatically develop the most suitable scaling prefix based on the measurement value.
Cheers, Sam.
source share