使用 Java 中的新 DecimalFormat("0.#####E0") 設定 double
首先,設定雙精度值 −
double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920;
現在,使用新的 DecimalFormat("0.#####E0") 格式化雙精度值 −
System.out.println(new DecimalFormat("0.#####E0").format(d1));
System.out.println(new DecimalFormat("0.#####E0").format(d2));
System.out.println(new DecimalFormat("0.#####E0").format(d3));以下是一個示例 −
示例
import java.text.DecimalFormat;
public class Demo {
public static void main(String[] argv) throws Exception {
double d1 = 1.39876;
double d2 = 2.39876;
double d3 = 0.66920;
System.out.println(new DecimalFormat("0.#####E0").format(d1));
System.out.println(new DecimalFormat("0.#####E0").format(d2));
System.out.println(new DecimalFormat("0.#####E0").format(d3));
}
}輸出
1.39876E0 2.39876E0 6.692E-1
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP