Description Of BigDecimal: subtract(BigDecimal subtrahend, MathContext mc)
The java.math.BigDecimal.subtract(BigDecimal subtrahend, MathContext mc) returns a BigDecimal whose value is (this - subtrahend) , with rounding according to the context settings. If subtrahend is zero then this, rounded if necessary, is used as the result. If this is zero then the result is subtrahend.negate(mc) .BigDecimal.subtract(BigDecimal subtrahend, MathContext mc) method returns this - subtrahend , 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("123.123"); BigDecimal bg2 = new BigDecimal("12.12"); MathContext mc = new MathContext(2); // 2 precision BigDecimal bg3 = bg1.subtract(bg2, mc); // print bg3 value System.out.println(bg3); } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น