java.math.BigDecimal.scaleByPowerOfTen(int n)%uA0返回一个BigDecimal,其数值等于 (this * 10n). 精度的结果是 (this.scale() - n).
声明
以下是java.math.BigDecimal.scaleByPowerOfTen()方法的声明
public BigDecimal scaleByPowerOfTen(int n)
参数
-
n%uA0- 由BigDecimal对象乘以10的幂值
返回值
此方法返回BigDecimal对象 this * 10n%uA0的值
异常
-
ArithmeticException%uA0- 如果精度是一个32位范围以外的整数
例子
下面的例子显示math.BigDecimal.scaleByPowerOfTen()方法的用法
package com.yiibai import java.math.* public class BigDecimalDemo { public static void main(String[] args) { // create 4 BigDecimal objects BigDecimal bg1, bg2, bg3, bg4 bg1 = new BigDecimal("235.000") bg2 = new BigDecimal("23500") // assign the result of method on bg1, bg2 to bg3, bg4 bg3 = bg1.scaleByPowerOfTen(3) bg4 = bg2.scaleByPowerOfTen(-3) String str1 = bg1 + " raised to 10 power 3 is " +bg3 String str2 = bg2 + " raised to 10 power -3 is " +bg4 // print bg3, bg4 values System.out.println( str1 ) System.out.println( str2 ) } }
让我们编译和运行上面的程序,这将产生以下结果:
235.000 raised to 10 power 3 is 235000 23500 raised to 10 power -3 is 23.500