javax.measure
Q - The quantitypublic class DecimalMeasure<Q extends Quantity> extends Measure<java.math.BigDecimal,Q>
This class represents a measure whose value is an arbitrary-precision decimal number.
When converting, applications may supply the java.math.Context:
DecimalMeasure<Velocity> c = DecimalMeasure.valueOf("299792458 m/s");
DecimalMeasure<Velocity> milesPerHour = c.to(MILES_PER_HOUR, MathContext.DECIMAL128);
System.out.println(milesPerHour);
> 670616629.3843951324266284896206156 mph
| Constructor and Description |
|---|
DecimalMeasure(java.math.BigDecimal value,
Unit<Q> unit)
Creates a decimal measure for the specified number stated in the specified unit.
|
| Modifier and Type | Method and Description |
|---|---|
Measurable<Q> |
add(Measurable<Q> other)
Adds the other Measurable to this one, returning a Measurable object of the same type as the original.
|
double |
doubleValue(Unit<Q> unit)
Returns the value of this measure stated in the specified unit as a
double. |
Unit<Q> |
getUnit()
Returns the measurement unit of this measure.
|
java.math.BigDecimal |
getValue()
Returns the measurement value of this measure.
|
DecimalMeasure<Q> |
to(Unit<Q> unit)
Returns the decimal measure equivalent to this measure but stated in the specified unit.
|
DecimalMeasure<Q> |
to(Unit<Q> unit,
java.math.MathContext mathContext)
Returns the decimal measure equivalent to this measure but stated in the specified unit, the conversion is
performed using the specified math context.
|
static <Q extends Quantity> |
valueOf(java.math.BigDecimal decimal,
Unit<Q> unit)
Returns the decimal measure for the specified number stated in the specified unit.
|
static <Q extends Quantity> |
valueOf(java.lang.CharSequence csq) |
public static <Q extends Quantity> DecimalMeasure<Q> valueOf(java.math.BigDecimal decimal, Unit<Q> unit)
Q - The quantitydecimal - the measurement value.unit - the measurement unit.public static <Q extends Quantity> DecimalMeasure<Q> valueOf(java.lang.CharSequence csq)
Q - The quantitycsq - the decimal measure representation (including unit if any).BigDecimal value, then the unit if any (value and unit should be separated by white spaces).java.lang.NumberFormatException - if the specified character sequence is not a valid representation of decimal measure.public Unit<Q> getUnit()
Measurepublic java.math.BigDecimal getValue()
Measurepublic DecimalMeasure<Q> to(Unit<Q> unit)
to in class Measure<java.math.BigDecimal,Q extends Quantity>unit - the new measurement unit.java.lang.ArithmeticException - if the converted measure value does not have a terminating decimal expansionto(Unit, MathContext)public DecimalMeasure<Q> to(Unit<Q> unit, java.math.MathContext mathContext)
unit - the new measurement unit.mathContext - the mathContext used to convert BigDecimal values or null if none.java.lang.ArithmeticException - if the result is inexact but the rounding mode is MathContext.UNNECESSARY or
mathContext.precision == 0 and the quotient has a non-terminating decimal expansion.public double doubleValue(Unit<Q> unit)
Measuredouble. If the measure has too
great a magnitude to be represented as a double, it will be converted to
Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate.doubleValue in interface Measurable<Q extends Quantity>doubleValue in class Measure<java.math.BigDecimal,Q extends Quantity>unit - the unit in which this measure is stated.double.public Measurable<Q> add(Measurable<Q> other)
Measurableother - The measurable that should be added to this one.