QuantityQ
Details
- QuantityQ[expr] returns False unless expr is a Quantity expression with valid arguments (i.e. has a canonical unit).
- QuantityQ[expr,dims] returns True if expr is a valid Quantity and is compatible with dims.
- Dimensional specification dims may be a list of unit dimensions, a QuantityVariable, a Quantity or a string representing a quantity variable or unit dimension.
Examples
open all close allBasic Examples (2)
QuantityQ tests whether an object is a Quantity with valid arguments:
QuantityQ[Quantity[3, "Feet"]]QuantityQ[Quantity[3, "Foo"]]QuantityQ[x]Test if an expression is a time quantity:
QuantityQ[Quantity[300, "Second"], "Time"]QuantityQ[Quantity[300, "Meters"], "Time"]Scope (3)
Dimension specifications may be a list of unit dimensions, QuantityVariable, Quantity or string:
QuantityQ[Quantity[300, "Meters"], {{"LengthUnit", 1}}]QuantityQ[Quantity[300, "Meters"], Height]QuantityQ[Quantity[300, "Meters"], Quantity[10, "Feet"]]QuantityQ[Quantity[300, "Meters"], "LengthUnit"]QuantityQ[Quantity[300, "Meters"], "Depth"]QuantityQ returns False if the first argument is not a valid Quantity expression:
QuantityQ[x, Acceleration]QuantityQ returns False if the second argument is not a recognized dimension specification:
QuantityQ[Quantity[3, "Meters"/"Seconds"], "foo"]QuantityQ[Quantity[3, "Meters"/"Seconds"], x]Applications (1)
QuantityQ can be used in pattern tests for functions:
foo[x_ ? QuantityQ] := QuantityMagnitude[x] ^ 2foo[Quantity[8, "Feet"]]foo[Quantity[8, "foo"]]Properties & Relations (3)
QuantityQ returns False for any expression whose head is not Quantity:
QuantityQ[2]QuantityQ[x]QuantityQ[{Quantity[7, "Weeks"], Quantity[2, "Hours"]}]In particular, QuantityArray, QuantityVariable, and QuantityDistribution are not QuantityQ objects:
QuantityQ[QuantityArray[{2.3, 1.5, 9.0}, "Meters"]]QuantityQ[QuantityVariable["V", "ElectricPotential"]]QuantityQ[QuantityDistribution[NormalDistribution[12, 6], "Centimeters"]]QuantityQ returns False for Quantity expressions with invalid arguments:
Quantity[2, x]QuantityQ[%]Quantity[2, Quantity["Meters"]]QuantityQ[%]QuantityQ returns True only for Quantity expressions with valid arguments:
Quantity[2, "Meters"]QuantityQ[%]Quantity[2, IndependentUnit["myUnit"] ^ 3]QuantityQ[%]Quantity[MixedMagnitude[{5, 10}],
MixedUnit[{"Feet", "Inches"}]]QuantityQ[%]See Also
Tech Notes
Related Guides
Related Workflows
- Calculate with Units
Text
Wolfram Research (2012), QuantityQ, Wolfram Language function, https://reference.wolfram.com/language/ref/QuantityQ.html (updated 2024).
CMS
Wolfram Language. 2012. "QuantityQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/QuantityQ.html.
APA
Wolfram Language. (2012). QuantityQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/QuantityQ.html
BibTeX
@misc{reference.wolfram_2026_quantityq, author="Wolfram Research", title="{QuantityQ}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/QuantityQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_quantityq, organization={Wolfram Research}, title={QuantityQ}, year={2024}, url={https://reference.wolfram.com/language/ref/QuantityQ.html}, note=[Accessed: 13-June-2026]}