As soon as you’re dealing with real-world quantities, it’s inevitable that you’ll run into units. In the Wolfram Language, you can enter quantities with units using (Key1[ctrl, =]).

LinguisticAssistant

LinguisticAssistant

(Quantity[2.6, "h", hours, "Hours"])

You can use InputForm to see how the Wolfram Language internally represents this.

InputForm[LinguisticAssistant]

You can always enter quantities directly like this, or you can use (Key1[ctrl, =]), either for the whole thing, or just for the units.

The Wolfram Language knows about all the 10,000 or so common kinds of units. UnitConvert converts between them.

UnitConvert[(Quantity[2.6, "h", hours, "Hours"]),"Minutes"]

You can do arithmetic with quantities even if they have different units.

LinguisticAssistant+LinguisticAssistant

LinguisticAssistant/LinguisticAssistant

You can compute with money too.

7.5*LinguisticAssistant+2.51*LinguisticAssistant

LinguisticAssistant*LinguisticAssistant

You can convert between currencies. The Wolfram Language always knows the latest conversion rate.

CurrencyConvert[LinguisticAssistant,LinguisticAssistant]

There are many places where units show up. Another example is in angles—and this is such a common case that the Wolfram Language lets you handle it in a special way. You can enter an angle like 30 degrees either as 30 Degree, or as 30°, where the ° can be typed as (Key0[esc]) deg (Key0[esc]).

Rotate["hello",30°]

If you leave off the Degree or °, the Wolfram Language will assume you’re talking about radians, which go from 0 to 2π (about 6.28) around a circle, rather than degrees, which go from 0 to 360.

Rotate["hello",Pi/2]

Table[Rotate[n,n Degree],{n,0,360,30}]

There’s lots to do with angles. For example, AnglePath gives the path you’d follow if you successively turned by a sequence of angles.

Graphics[Line[AnglePath[{0°,80°,80°,80°}]]]

Graphics[Line[AnglePath[Table[80°,20]]]]

Graphics[Line[AnglePath[Table[n*5°,{n,200}]]]]

Convert 4.5 lbs (pounds) to kilograms. »

Convert 60.25 mph to kilometers per hour. »

Find the height of the Eiffel Tower in miles. »

Find the height of Mount Everest divided by the height of the Eiffel Tower. »

Find the mass of the Earth divided by the mass of the Moon. »

Convert 2500 Japanese yen to US dollars. »

Find the total of 35 ounces, 1/4 ton, 45 lbs and 9 stone in kilograms. »

Get a list of the distances to each planet using the "DistanceFromEarth" property, and convert all the results to light minutes. »

Rotate the string "hello" by 180°. »

Make a table of a size-100 “A” rotated by 0° through 360° in steps of 30°. »

Make a Manipulate to rotate an image of a cat between 0° and 180°. »

Generate graphics for a path obtained by turning 0°, 1°, 2°, ... , 180°. »

Make graphics of the path obtained by turning a constant angle 100 times, controlling the angle from 0° to 360° with a Manipulate. »

Make graphics of the path obtained by successively turning by the digits of 2^10000 multiplied by 30°. »

Convert 4.3 light years to furlongs. »

Convert 20,000 leagues to miles. »

Make a Manipulate to rotate a size-200 “W” to any angle from 0° to 360°. »

Rotate an image of the Great Pyramid by 180°. »

Generate a list of letters of the alphabet, each randomly rotated. »

Generate graphics for a path obtained by turning 100 times through a random number of degrees between 0 and 360. »

What unit abbreviations does the Wolfram Language understand?

Pretty much any common abbreviation, whether it’s miles/hr or mph or mi/h, etc. (If you’re wondering if an abbreviation will work, just try it.)

Does the Wolfram Language pick units based on what country I’m in?

Yes. For example, it’ll tend to use inches if you’re in the US, and centimeters if you’re in continental Europe.

Do I have to be connected to the network to use units?

Only to interpret input like 5 kg. If you type Quantity[5,"Kilograms"] you don’t need the network—except to deal with units like currencies whose values are always changing.

What can I do if my unit conversion gives me an exact fraction but I want a decimal number?

Use the function N[...] to find a decimal approximation. Or add a decimal point to a number in your input. We’ll talk more about this in Section 23.

Why don’t I get the same result for the currency conversion example?

Because, without doubt, the conversion rates have changed.

Tech Notes