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