Description Of BigDecimal: plus(MathContext mc)
The java.math.BigDecimal.plus(MathContext mc) returns a BigDecimal whose value is (+this) , with rounding according to the context settings.BigDecimal.plus(MathContext mc) method returns this , rounded as necessary. A zero result will have a scale of 0.
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("-75.312"); BigDecimal bg2 = new BigDecimal("25.24212"); MathContext mc = new MathContext(4);// 4 precision BigDecimal bg3 = bg1.plus(mc); BigDecimal bg4 = bg2.plus(mc); // print bg3, bg4 values System.out.println(bg3); System.out.println(bg4); } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น