Java Math BigDecimal.shortValueExact() 方法


Java Math BigDecimal.shortValueExact() 方法

package com.codingdict;



import java.math.*;



public class BigDecimalDemo {



   public static void main(String[] args) {



      // create 2 BigDecimal objects

      BigDecimal bg1, bg2;



      // create 2 short objects

      short s1, s2;



      bg1 = new BigDecimal("235");

      bg2 = new BigDecimal("4364");



      // assign the short value of bg1 and bg2 to s1,s2 respectively

      s1 = bg1.shortValueExact();

      s2 = bg2.shortValueExact();



      String str1 = "Exact short value of " + bg1 + " is " + s1;

      String str2 = "Exact short value of " + bg2 + " is " + s2;



      // print s1,s2 values

      System.out.println( str1 );

      System.out.println( str2 );

   }

}