I'm writing a web based front end for an engineering simulation. The back end only accepts values in non-prefixed SI units, such as meters or watts. However it would be preferable to allow the user to enter values in any unit they wish. For example, if you needed to enter a distance, you could enter:
15 inches
3.1 meter
1.4 km
but values such as:
12 seconds
5 pounds
147 watts
would be rejected. I first tried using js-quantities, but it doesn't parse derived units in the most intuitive way. It requires a space to be placed between each multiplied unit. For example, to enter an amount of charge in amp hours, 100 Ah
is invalid, but 100 A h
is acceptable. Additionally, js-quantities does not support units of torque or temperature (only temperature difference, you can't convert Fahrenheit to Celsius for example)
I then tried to use the google calculator API to do unit conversions, but it produces hard to parse results for small numbers:
Convert 5 nm to meters
request:
http://www.google.com/ig/calculator?hl=en&q=5%20nm=?m
response:
{lhs: "5 nanometers",rhs: "5.0 \x26#215; 10\x3csup\x3e-9\x3c/sup\x3e meters",error: "",icc: false}