public final class Quantities extends Object
Quantity
instances.Modifier and Type | Method and Description |
---|---|
static ComparableQuantity<?> |
getQuantity(CharSequence csq)
Returns the
decimal measure of unknown type corresponding to the specified
representation. |
static <Q extends javax.measure.Quantity<Q>> |
getQuantity(Number value,
javax.measure.Unit<Q> unit)
Returns the scalar measurement.
|
public static ComparableQuantity<?> getQuantity(CharSequence csq)
decimal
measure of unknown type corresponding to the specified
representation. This method can be used to parse dimensionless quantities.
Quantity proportion = Quantities.getQuantity("0.234").asType(Dimensionless.class);
Note: This method handles only standard
unit format (UCUM based). Locale-sensitive measure formatting and parsing are handled by the MeasurementFormat
class and its subclasses.
csq
- the decimal value and its unit (if any) separated by space(s).QuantityFormat.getInstance(LOCALE_NEUTRAL).parse(csq, new ParsePosition(0))
public static <Q extends javax.measure.Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, javax.measure.Unit<Q> unit)
Number
was BigDecimal
or BigInteger
will uses DecimalQuantity
, when the
Number
was Double
will DoubleQuantity
otherwise will NumberQuantity
. in the specified unit.value
- the measurement value.unit
- the measurement unit.numeric
measurement.NullPointerException
- when value or unit were nullCopyright © 2005–2019 Units of Measurement project. All rights reserved.