วันจันทร์ที่ 22 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: divideAndRemainder(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.

Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) method returns a two element BigDecimal array: the quotient (the result of divideToIntegralValue ) is the initial element and the remainder is the final element.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("1000.12");
  BigDecimal bg2 = new BigDecimal("332.32");

  MathContext mc = new MathContext(3);
  
  BigDecimal bg[] = bg1.divideAndRemainder(bg2, mc);

     System.out.println("Quotient is " + bg[0]);
     System.out.println("Remainder is " + bg[1]);
 }
}


yengo หรือ buzzcity

ไม่มีความคิดเห็น :

แสดงความคิดเห็น