# Can I format units using engineering prefixes?

I'm in the early stages of learning about units. It seems easy enough to express numerics and symbolics in units, but what I would really like to do is append engineering prefixes (km, mA, MW, etc). For instance, a value of 22000 volts should be represented as 22 kV. A value of 0.005 Amperes should be represented as 5 mA. A value of 0.00255 joules should be represented as 25.5 mJ. Like in the following:

Can this be done?

• What do you mean by "prefixes"? Of course km, mA, etc. are not prefixes at all. So what do you really want? Sep 15, 2017 at 20:35
• Could you add an example of input and expected output? Together with a little background?
– Kuba
Sep 15, 2017 at 20:38
• @Kuba as requested Sep 15, 2017 at 21:37

Here is a purposefully incomplete solution which I'll leave you to adapt to your needs:

pref = AssociationThread[Delete[Range[-2, 2], 3] -> {"Centi", "Deci", "Deka", "Hecto"}];
pref3 = AssociationThread[Delete[Range[-8, 8], 9] ->
{"Yocto", "Zepto", "Atto", "Femto", "Pico", "Nano", "Micro",
"Milli", "Kilo", "Mega", "Giga", "Tera", "Peta", "Exa",
"Zetta", "Yotta"}];

val = 1.95*^13; (* some sample value *)

{m, e} = {10 #1, #2 - 1} & @@ MantissaExponent[val];
s = Sign[e];
{q, r} = QuotientRemainder[Abs[e], 3];
If[q == 0, {m, Lookup[pref, s r, 1]},
{m 10^r, Lookup[pref3, s q, 1]}]


which should yield {19.5, "Tera"} in this case.

• I need to do some reading to understand this, so please don't get mad if I don't accept right away :) Sep 16, 2017 at 18:11
• Nobody's rushing you to accept at once, AFAICT. :) Just as long as you accept when you finally decide on what is most satisfactory for you. Sep 16, 2017 at 18:13
UnitConvert[Quantity[8.,"Meters"],"Kilometers"]


0.008 km

What do you mean by engineering "prefixes"?

Is this what you're seeking?

Quantity[8, "Meters"]


8 m

Quantity[10, "Centimeters"]


10 cm

Quantity[20, "Feet"]


20 ft

• No, I mean a general interconversion between x*(10^3n) and a unit abbreviation, not only for length. I will change my question to reflect this. Sep 15, 2017 at 19:04
• And, obviously, put a decimal point where its supposed to go :) Sep 15, 2017 at 19:07