Java 中的 DecimalFormat("000000E0")

java 8object oriented programmingprogramming

DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数。让我们设置 DecimalFormat("000000E0") 并使用 format() 方法。

new DecimalFormat("000000E0").format(199)
new DecimalFormat("000000E0").format(29089)

由于我们在 Java 中使用了 DecimalFormat 类,因此必须导入以下包 −

import java.text.DecimalFormat;

以下是完整示例 −

示例

import java.text.DecimalFormat;
public class Demo {
   public static void main(String[] argv) throws Exception {
      System.out.println(new DecimalFormat("000000E0").format(199));
      System.out.println(new DecimalFormat("000000E0").format(29089));
      System.out.println(new DecimalFormat("000000E0").format(398987));
      System.out.println(new DecimalFormat("000000E0").format(498989));
      System.out.println(new DecimalFormat("000000E0").format(6989898));
      System.out.println(new DecimalFormat("000000E0").format(7688888));
   }
}

输出

199000E-3
290890E-1
398987E0
498989E0
698990E1
768889E1

相关文章