- Java.math 包中的额外内容
- Java.math - 枚举
- Java.math - 讨论
Java.math.BigDecimal.stripTrailingZeros() 方法
说明
java.math.BigDecimal.stripTrailingZeros() 将返回一个数值等于此数值但移除了表示中所有前置零的 BigDecimal。
例如,从 BigDecimal 值 600.0 中移除前置零(其 [BigInteger, scale] 分量等于 [6000, 1])将生成 6E2,其 [BigInteger, scale] 分量等于 [6, -2]。
声明
以下是 java.math.BigDecimal.stripTrailingZeros() 方法的声明。
public BigDecimal stripTrailingZeros()
参数
不适用
返回值
此方法将返回一个移除了所有前置零的等值的 BigDecimal。
异常
不适用
示例
以下示例显示了 math.BigDecimal.stripTrailingZeros() 方法的用法。
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 stripTrailingZeros method to bg3, bg4
bg3 = bg1.stripTrailingZeros();
bg4 = bg2.stripTrailingZeros();
String str1 = bg1 + " after removing trailing zeros " +bg3;
String str2 = bg2 + " after removing trailing zeros " +bg4;
// print bg3, bg4 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行以上程序,其将生成以下结果:
235.000 after removing trailing zeros 235 23500 after removing trailing zeros 2.35E+4
java_math_bigdecimal.htm
广告