วันพฤหัสบดีที่ 2 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.add(BigDecimal augend, MathContext mc)

Description Of BigDecimal: add(BigDecimal augend, MathContext mc)

The java.math.BigDecimal.add(BigDecimal augend, MathContext mc) returns a BigDecimal whose value is (this + augend) , with rounding according to the context settings. If either number is zero and the precision setting is nonzero then the other number, rounded if necessary, is used as the result

BigDecimal.add(BigDecimal augend, MathContext mc) method returns this + augend , rounded as necessary.

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("12.345");
     BigDecimal bg2 = new BigDecimal("23.456");

     System.out.println("Object Value is " + bg1);
     System.out.println("Augend value is " + bg2);

     // create MathContext object with 4 precision
     MathContext mc = new MathContext(4);

     // perform add operation on bg1 with augend bg2 and context mc
     BigDecimal bg3 = bg1.add(bg2, mc);

     System.out.println("Result is " + bg3);
 }
}


yengo หรือ buzzcity

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

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