Java Math BigDecimal longValue() 方法 Java Math BigDecimal IntValueExact() Java Math BigDecimal.longValueExact() 方法 Java Math BigDecimal longValue() 方法 package com.codingdict; import java.math.*; public class BigDecimalDemo { public static void main(String[] args) { // create 2 BigDecimal objects BigDecimal bg1, bg2; // create 2 long objecs long l1,l2; bg1 = new BigDecimal("429.07"); bg2 = new BigDecimal("429496732223453626252"); // assign the long value of bg1 and bg2 to l1,l2 respectively l1 = bg1.longValue(); l2 = bg2.longValue(); String str1 = "long value of " + bg1 + " is " + l1; String str2 = "long value of " + bg2 + " is " + l2; // print l1,l2 values System.out.println( str1 ); System.out.println( str2 ); } } Java Math BigDecimal IntValueExact() Java Math BigDecimal.longValueExact() 方法