Java中的十进制格式

Java中的十进制格式,java,decimalformat,Java,Decimalformat,我在这里寻找答案,但我找不到,如果有其他帖子讨论这个问题,我很抱歉,但是,我的答案很简单,我肯定,但我看不到,我如何设置十进制格式,如: 7.9820892389040892803E-05 我想对数字进行格式化以保留“E”,但将小数格式化为: 7.98203E-05 如果有人能把灯给我看,我会非常感激。你可以使用十进制格式(): 例如: DecimalFormat formatter = new DecimalFormat("#.#####E00"); System.out.printl

我在这里寻找答案,但我找不到,如果有其他帖子讨论这个问题,我很抱歉,但是,我的答案很简单,我肯定,但我看不到,我如何设置十进制格式,如:

 7.9820892389040892803E-05
我想对数字进行格式化以保留“E”,但将小数格式化为:

 7.98203E-05

如果有人能把灯给我看,我会非常感激。

你可以使用
十进制格式
():

例如:

DecimalFormat formatter = new DecimalFormat("#.#####E00");
System.out.println(formatter.format(7.9820892389040892803E-05));
System.out.println(formatter.format(7.98E-05));
输出:

7.98209E-05
7.98E-05
7.98000E-05
请注意,使用
#
时,不会打印尾随的零。如果您总是希望小数点后有五位数字,则应使用
0

DecimalFormat formatter = new DecimalFormat("0.00000E00");
System.out.println(formatter.format(7.98E-05));
输出:

7.98209E-05
7.98E-05
7.98000E-05

您可以使用
DecimalFormat
():

例如:

DecimalFormat formatter = new DecimalFormat("#.#####E00");
System.out.println(formatter.format(7.9820892389040892803E-05));
System.out.println(formatter.format(7.98E-05));
输出:

7.98209E-05
7.98E-05
7.98000E-05
请注意,使用
#
时,不会打印尾随的零。如果您总是希望小数点后有五位数字,则应使用
0

DecimalFormat formatter = new DecimalFormat("0.00000E00");
System.out.println(formatter.format(7.98E-05));
输出:

7.98209E-05
7.98E-05
7.98000E-05

您可以使用

您需要的格式是
%.5E
(=大写科学符号的精度5)


示例:
System.out.printf(“%.5E”,5/17d)打印
2.94118E-01

您可以使用

您需要的格式是
%.5E
(=大写科学符号的精度5)


示例:
System.out.printf(“%.5E”,5/17d)打印
2.94118E-01

使用DeciamlFormat对象

public static void main(String[] args) {
        double amount = 7.9820892389040892803E-05;
        DecimalFormat df = new DecimalFormat("0.00000E0");
        System.out.println(df.format(amount));
}
结果:


使用DeciamlFormat对象

public static void main(String[] args) {
        double amount = 7.9820892389040892803E-05;
        DecimalFormat df = new DecimalFormat("0.00000E0");
        System.out.println(df.format(amount));
}
结果:

或者什么什么的