Description Of BigDecimal: intValueExact()
The java.math.BigDecimal.intValueExact() converts this BigDecimal to an int , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for an int result then an ArithmeticException is thrown.BigDecimal.intValueExact() method returns this BigDecimal converted to an int .
Code Example Java BigDecimal
import java.math.BigDecimal; public class BigDecimalExam { public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("-75"); BigDecimal bg2 = new BigDecimal("25"); BigDecimal bg3 = new BigDecimal("25"); int b1 = bg1.intValueExact(); int b2 = bg2.intValueExact(); int b3 = bg3.intValueExact(); System.out.println(b1); System.out.println(b2); System.out.println(b3); } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น