Description Of BigDecimal: longValueExact()
The java.math.BigDecimal.longValueExact() converts this BigDecimal to a long , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a long result then an ArithmeticException is thrown.BigDecimal.longValueExact() method returns this BigDecimal converted to a long .
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"); long b1 = bg1.longValueExact(); long b2 = bg2.longValueExact(); long b3 = bg3.longValueExact(); System.out.println(b1); System.out.println(b2); System.out.println(b3); } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น