Description Of BigDecimal: shortValueExact()
The java.math.BigDecimal.shortValueExact() converts this BigDecimal to a short , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown.BigDecimal.shortValueExact() method returns this BigDecimal converted to a short.
Code Example Java BigDecimal
import java.math.BigDecimal;
public class BigDecimalExam {
public static void main(String[] args) {
BigDecimal bg1 = new BigDecimal("215");
BigDecimal bg2 = new BigDecimal("1214");
short s1 = bg1.shortValueExact();
short s2 = bg2.shortValueExact();
String str1 = "Exact short value of " + bg1 + " is " + s1;
String str2 = "Exact short value of " + bg2 + " is " + s2;
System.out.println(str1);
System.out.println(str2);
}
}
ไม่มีความคิดเห็น :
แสดงความคิดเห็น