The International System of Units is a system of measuring all around the world, except for a few countries including the US. The SI system (or metric system) is based on powers of ten, listed below (note that this is an incomplete table):
femto(f) pico(p) nano(n) micro(μ) milli(m) centi(c) (base unit) hecto(h) kilo(k) mega(M) giga(G) tera(T) peta(P) 10^-15 10^-12 10^-9 10^-6 10^-3 10^-2 10^0 10^2 10^3 10^6 10^9 10^12 10^15
Your job will to be to take in one of these measures and convert it into another.
Input will be a decimal number
10^-16 < x < 2^31 - 1, an SI prefix, a letter representing a quantity, another SI prefix to convert to, and the same quantity letter. Input will be in the format
1234.56 mC to TC, and will always match with the regex
^\d+(\.\d+)? [fpnμmchkMGTP](?'letter'[a-zA-Z]) to [fpnμmchkMGTP](?P=letter)$. You will never have to convert to/from the base unit (
Output will be the same number as the input, just converted to a new SI prefix. Specifically, the program should convert the number from
SI prefix 1 to
SI prefix 2 in the input. Examples:
Input: 1 nm to μm Output: 0.001 Input: 82 kC to cC Output: 8200000 Input: 6.54 MK to hK Output: 65400 Input: 2000 MB to GB Output: 2
This is code-golf, so shortest code in bytes wins!