Package com.google.common.math
Class BigDecimalMath
- java.lang.Object
- 
- com.google.common.math.BigDecimalMath
 
- 
 @GwtIncompatible public class BigDecimalMath extends Object A class for arithmetic onBigDecimalthat is not covered by its built-in methods.- Since:
- 30.0
- Author:
- Louis Wasserman
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleroundToDouble(BigDecimal x, RoundingMode mode)Returnsx, rounded to adoublewith the specified rounding mode.
 
- 
- 
- 
Method Detail- 
roundToDoublepublic static double roundToDouble(BigDecimal x, RoundingMode mode) Returnsx, rounded to adoublewith the specified rounding mode. Ifxis precisely representable as adouble, itsdoublevalue will be returned; otherwise, the rounding will choose between the two nearest representable values withmode.For the case of RoundingMode.HALF_DOWN,HALF_UP, andHALF_EVEN, infinitedoublevalues are considered infinitely far away. For example, 2^2000 is not representable as a double, butroundToDouble(BigDecimal.valueOf(2).pow(2000), HALF_UP)will returnDouble.MAX_VALUE, notDouble.POSITIVE_INFINITY.For the case of RoundingMode.HALF_EVEN, this implementation uses the IEEE 754 default rounding mode: if the two nearest representable values are equally near, the one with the least significant bit zero is chosen. (In such cases, both of the nearest representable values are even integers; this method returns the one that is a multiple of a greater power of two.)- Throws:
- ArithmeticException- if- modeis- RoundingMode.UNNECESSARYand- xis not precisely representable as a- double
- Since:
- 30.0
 
 
- 
 
-