Description Of BigDecimal: abs(MathContext mc)
The java.math.BigDecimal.abs(MathContext mc) returns a BigDecimal whose value is the absolute value of this BigDecimal , with rounding according to the context settings.BigDecimal.abs(MathContext mc) method returns abs(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) { MathContext mc = new MathContext(3); MathContext mc1 = new MathContext(4); BigDecimal bg1 = new BigDecimal("123.1234"); // assign absolute value of bg1 to bg2 rounded to 2 precision using mc BigDecimal bg2 = bg1.abs(mc); // assign absolute value of bg1 to bg3 rounded to 4 precision using mc1 BigDecimal bg3 = bg1.abs(mc1); System.out.println(bg2); System.out.println(bg3); } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น