DecimalFormat("00E00") 在 Java 中
DecimalFormat 是 NumberFormat 的一個具體子類,用於格式化十進位制數。
我們先來設定 DecimalFormat("00E00")。
Format f = new DecimalFormat("00E00");現在,我們將格式化一個數字並將結果顯示在一個字串中,使用 format() 方法 -
String res = f.format(-5977.3427);
由於我們在 Java 中同時使用了 Format 和 DecimalFormat 類,因此必須匯入以下包 -
import java.text.DecimalFormat; import java.text.Format;
以下是完整示例 -
示例
import java.text.DecimalFormat;
import java.text.Format;
public class Demo {
public static void main(String[] argv) throws Exception {
Format f = new DecimalFormat("00E00");
String res = f.format(-5977.3427);
System.out.println(res);
}
}輸出
-60E02
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP