"Quantity" (interpreter type)

Natural-language quantity with units.

DetailsDetails

  • "Quantity" can be used in Interpreter and related constructs, including deployed smart form fields.
  • Use of "Quantity" requires connectivity to the Wolfram Cloud.

Allowed FormsAllowed Forms

  • All the natural-language numbers allowed by "SemanticNumber" are supported for the quantity magnitude.
  • Examples of unit specifications include:
  • one dimenatural-language units
    8.9 hours per day/personcompound units
    30 °Cunit abbreviations and symbols
    10 milespostfix units
    $99.99prefix units

Restriction SpecificationsRestriction Specifications

  • Restricted["Quantity",{{choices1,}}]one among choices
    Restricted["Quantity",unit]convert to unit
    Restricted["Quantity",quantityvariable]restrict to units compatible with the phyisical quantity of quantityvariable
    Restricted["Quantity",unit,max]a quantity below Quantity[max,unit]
    Restricted["Quantity",unit,{min,max}]a quantity between Quantity[min,unit] and Quantity[max,unit]
    Restricted["Quantity",unit,{min,max,s}]a quantity between Quantity[min,unit] and Quantity[max,unit] with step s
    Restricted["Quantity",quantityvariable,max]a quantity below Quantity[max,unit], with unit the canonical unit of quantityvariable
  • The bounds min and max and step s can also be expressed as quantities.

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Interpret quantities of any kind:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Interpret quantities in natural language:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Restrict and convert to a unit:

In[1]:=
Click for copyable input
Out[1]=

Restrict in an interval:

In[1]:=
Click for copyable input
Out[1]=

Restrict to a given physical quantity:

In[1]:=
Click for copyable input
Out[1]=

Accept unit-less inputs in the presence of an appropriate restriction:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=