DecimalFormat("000000E0") 於 Java 中
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP