Java Math BigDecimal IntValueExact() Java Math BigDecimal.intValue() Java Math BigDecimal longValue() 方法 Java Math BigDecimal IntValueExact() package com.codingdict; import java.math.*; public class BigDecimalDemo { public static void main(String[] args) { // create 2 BigDecimal objects BigDecimal bg1, bg2; //Create two int Object int i1, i2; bg1 = new BigDecimal("40"); bg2 = new BigDecimal("4E+1"); // assign the exact int value of bg1 and bg2 to i1,i2 respectively i1 = bg1.intValueExact(); i2 = bg2.intValueExact(); String str1 = "Exact int value of " + bg1 + " is " + i1; String str2 = "Exact int value of " + bg2 + " is " + i2; // print i1,i2 values System.out.println( str1 ); System.out.println( str2 ); } } Java Math BigDecimal.intValue() Java Math BigDecimal longValue() 方法