
- Java.math 包的額外資訊
- Java.math - 列舉
- Java.math - 討論
Java.math.BigDecimal.scaleByPowerOfTen() 方法
說明
java.math.BigDecimal.scaleByPowerOfTen(int n) 返回與其數值等價的 BigDecimal,即 (this * 10n)。結果的標度為 (this.scale() - n)。
宣告
以下是 java.math.BigDecimal.scaleByPowerOfTen() 方法的宣告。
public BigDecimal scaleByPowerOfTen(int n)
引數
n − BigDecimal 物件乘以十的 n 次方的值。
返回值
此方法返回值為 this * 10n 的 BigDecimal 物件。
異常
ArithmeticException − 如果標度超出 32 位整數的範圍。
示例
以下示例演示了 math.BigDecimal.scaleByPowerOfTen() 方法的用法。
package com.tutorialspoint; 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
java_math_bigdecimal.htm
廣告