In the development of high-precision operation is not very frequent, the precision of float and double can actually meet the overwhelming majority of needs, and high-precision operation is slower than the normal operation, but the use of high-precision operation is often used in the convenient API. The class of high precision operations provided by the Crown is mainly two
BigInteger: When the range of values exceeds long, use BigDecimal: almost cover the BigInteger function, you can also retain any number of decimal places, theoretically infinite, the following main explanation of this class
Note: Both APIs are similar
Subtraction
BigDecimal AAA = new BigDecimal (20);
BigDecimal bbb = new BigDecimal (3);
BigDecimal AAA. Add (BBB): an addition operation that returns the result of an operation
BigDecimal AAA. Subtract (BBB): subtraction, returns the result of an operation
BigDecimal AAA. Multiply (BBB): multiplication, returning result after operation
BigDecimal AAA. Divide (BBB): division operation, returning result after operation
Keep decimal points
Mainly for the division operation, there may be an infinite number of decimals, if not rounding operation will be an error
BigDecimal result = Aaa.divide (BBB, 8, BIGDECIMAL.ROUND_HALF_UP);
Parameter 1: Divisor
Parameter 2: Reserved precision, requires retention of several decimals
Parameter 3: Rounding mode, often several rounding methods
BIGDECIMAL.ROUND_HALF_UP: Rounding
Bigdecimal.round_ceiling: Rounding the upper limit value, such as the result of 1.1, returns 2
Bigdecimal.round_floor: Rounding lower values, such as 1.8, returns 1
Other APIs
* *value (): Convert to basic data type such as Aaa.intvalue (), Aaa.doublevalue (), etc.
BigInteger Tobiginteger (): Convert to BigInteger type
Bigdecimal.zero: Rep 0
Bigdecimal.one: Rep 1
Bigdecimal.ten: Rep 10
High-precision Operation