Package javax.measure
Class DecimalMeasure<Q extends Quantity>
- All Implemented Interfaces:
Serializable,Comparable<Measurable<Q>>,Measurable<Q>
This class represents a measure whose value is an arbitrary-precision decimal number.
When converting, applications may supply the
java.math.Context:[code]
DecimalMeasure
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDecimalMeasure(BigDecimal value, Unit<Q> unit) Creates a decimal measure for the specified number stated in the specified unit. -
Method Summary
Modifier and TypeMethodDescriptiondoubledoubleValue(Unit<Q> unit) Returns the value of this measure stated in the specified unit as adouble.getUnit()Returns the measurement unit of this measure.getValue()Returns the measurement value of this measure.Returns the decimal measure equivalent to this measure but stated in the specified unit.to(Unit<Q> unit, 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>
DecimalMeasure<Q>valueOf(CharSequence csq) Returns the decimal measure for the specified textual representation.static <Q extends Quantity>
DecimalMeasure<Q>valueOf(BigDecimal decimal, Unit<Q> unit) Returns the decimal measure for the specified number stated in the specified unit.
-
Constructor Details
-
DecimalMeasure
Creates a decimal measure for the specified number stated in the specified unit.
-
-
Method Details
-
valueOf
Returns the decimal measure for the specified number stated in the specified unit.- Parameters:
decimal- the measurement value.unit- the measurement unit.
-
valueOf
Returns the decimal measure for the specified textual representation. This method first reads theBigDecimalvalue, then the unit if any (value and unit should be separated by white spaces).- Parameters:
csq- the decimal measure representation (including unit if any).- Throws:
NumberFormatException- if the specified character sequence is not a valid representation of decimal measure.
-
getUnit
Description copied from class:MeasureReturns the measurement unit of this measure.- Specified by:
getUnitin classMeasure<BigDecimal,Q extends Quantity> - Returns:
- the measurement unit.
-
getValue
Description copied from class:MeasureReturns the measurement value of this measure.- Specified by:
getValuein classMeasure<BigDecimal,Q extends Quantity> - Returns:
- the measurement value.
-
to
Returns the decimal measure equivalent to this measure but stated in the specified unit. This method will raise an ArithmeticException if the resulting measure does not have a terminating decimal expansion.- Specified by:
toin classMeasure<BigDecimal,Q extends Quantity> - Parameters:
unit- the new measurement unit.- Returns:
- the measure stated in the specified unit.
- Throws:
ArithmeticException- if the converted measure value does not have a terminating decimal expansion- See Also:
-
to
Returns the decimal measure equivalent to this measure but stated in the specified unit, the conversion is performed using the specified math context.- Parameters:
unit- the new measurement unit.mathContext- the mathContext used to convertBigDecimalvalues ornullif none.- Returns:
- the measure stated in the specified unit.
- Throws:
ArithmeticException- if the result is inexact but the rounding mode isMathContext.UNNECESSARYormathContext.precision == 0 and the quotient has a non-terminating decimal expansion.
-
doubleValue
Description copied from class:MeasureReturns the value of this measure stated in the specified unit as adouble. If the measure has too great a magnitude to be represented as adouble, it will be converted toDouble.NEGATIVE_INFINITYorDouble.POSITIVE_INFINITYas appropriate.- Specified by:
doubleValuein interfaceMeasurable<Q extends Quantity>- Specified by:
doubleValuein classMeasure<BigDecimal,Q extends Quantity> - Parameters:
unit- the unit in which this measure is stated.- Returns:
- the numeric value after conversion to type
double.
-