Quantity

Quantity

Quantity[ value, unit ] represents a value with a unit (e.g. meters, euros, minutes).

Usages

Quantity[ value, unit ]

Quantity[ value, unit ] represents value with the unit unit. The unit must be written between single quotes. Units can be combined, for example 'm'/'s'^2.

Example in rendered
A length. Quantity[ 3, 'm' ] 3m3\;\mathrm{m}
An amount of money. Quantity[ 2.4, '€' ] or Quantity[ 2.4, 'euro' ] € 2.40
An angle in degrees. Quantity[ 30, 'deg' ] 30∘30^{\circ}
A combined unit. Quantity[ 9.81, 'm'/'s'^2 ] 9.81ms-29.81\;\mathrm{m}\;\mathrm{s}^{\text{-}2}

Quantity[ Text[ `text` ], unit ]

A text with a unit, for example to show the form of an answer.

Example in rendered
Write your answer in the form € amount. Quantity[ Text[`amount`], 'euro' ] € amount
Details
  • Calculations with quantities are done by Simplify, including conversion between units:
Example in out
Not calculated in a script. Quantity[2, 'm'] + Quantity[3, 'm'] Quantity[2, 'm'] + Quantity[3, 'm']
Add two lengths. Simplify[ Quantity[2, 'm'] + Quantity[3, 'm'] ] Quantity[5, 'm']
Different units are converted. Simplify[ Quantity[2, 'm'] + Quantity[30, 'cm'] ] Quantity[230, 'cm']
Multiply by a number. Simplify[ 2 * Quantity[3, 'm'] ] Quantity[6, 'm']
  • Lists: Quantity[ {1, 2}, 'm' ] gives {Quantity[1, 'm'], Quantity[2, 'm']}.
  • The value of a quantity is its first element: Quantity[3, 'm'][[1]] gives 3.
  • See the unit commands for the available units and for commands that work with units.
Warning

Write the unit between single quotes. Without quotes, as in Quantity[3, m], m is a variable, not a unit.

See also: RemoveFunction, Max, Convert