Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 指数精度[打印双精度,微小数字]_Java_Precision_Exponential - Fatal编程技术网

Java 指数精度[打印双精度,微小数字]

Java 指数精度[打印双精度,微小数字],java,precision,exponential,Java,Precision,Exponential,有没有一种打印精度达到指数级的方法? 我需要用微小的数字填充一些数据,并在…之后进行比较 我喜欢这样: (0) - Mesured estimatedTime for multithread in block: 1.4917951E16 s (1) - Mesured estimatedTime for multithread in block: 7.531891E15 s (2) - Mesured estimatedTime for multithread in block: 2.9287E

有没有一种打印精度达到指数级的方法? 我需要用微小的数字填充一些数据,并在…之后进行比较

我喜欢这样:

(0) - Mesured estimatedTime for multithread in block: 1.4917951E16 s
(1) - Mesured estimatedTime for multithread in block: 7.531891E15 s
(2) - Mesured estimatedTime for multithread in block: 2.9287E13 s
(3) - Mesured estimatedTime for multithread in block: 3.28478435E17 s
(4) - Mesured estimatedTime for multithread in block: 6.038E12 s
(0) - Mesured estimatedTime for original in block: 0000.15595175E15 s           
(1) - Mesured estimatedTime for original in block: 0007.335638E15 s             
(2) - Mesured estimatedTime for original in block: 0416.66E15 s                 
(3) - Mesured estimatedTime for original in block: 0000.0390156852E15 s         
(4) - Mesured estimatedTime for original in block: 6642.0E15 s
// Force minimum number of digits to left and right of decimal point
formatter = new DecimalFormat("0.0E0");
s = formatter.format(-1234.567);         // -1.2E3
我想这样打印:

(0) - Mesured estimatedTime for multithread in block: 1.4917951E16 s
(1) - Mesured estimatedTime for multithread in block: 7.531891E15 s
(2) - Mesured estimatedTime for multithread in block: 2.9287E13 s
(3) - Mesured estimatedTime for multithread in block: 3.28478435E17 s
(4) - Mesured estimatedTime for multithread in block: 6.038E12 s
(0) - Mesured estimatedTime for original in block: 0000.15595175E15 s           
(1) - Mesured estimatedTime for original in block: 0007.335638E15 s             
(2) - Mesured estimatedTime for original in block: 0416.66E15 s                 
(3) - Mesured estimatedTime for original in block: 0000.0390156852E15 s         
(4) - Mesured estimatedTime for original in block: 6642.0E15 s
// Force minimum number of digits to left and right of decimal point
formatter = new DecimalFormat("0.0E0");
s = formatter.format(-1234.567);         // -1.2E3
我知道你可以这样强迫它:

(0) - Mesured estimatedTime for multithread in block: 1.4917951E16 s
(1) - Mesured estimatedTime for multithread in block: 7.531891E15 s
(2) - Mesured estimatedTime for multithread in block: 2.9287E13 s
(3) - Mesured estimatedTime for multithread in block: 3.28478435E17 s
(4) - Mesured estimatedTime for multithread in block: 6.038E12 s
(0) - Mesured estimatedTime for original in block: 0000.15595175E15 s           
(1) - Mesured estimatedTime for original in block: 0007.335638E15 s             
(2) - Mesured estimatedTime for original in block: 0416.66E15 s                 
(3) - Mesured estimatedTime for original in block: 0000.0390156852E15 s         
(4) - Mesured estimatedTime for original in block: 6642.0E15 s
// Force minimum number of digits to left and right of decimal point
formatter = new DecimalFormat("0.0E0");
s = formatter.format(-1234.567);         // -1.2E3
但我不知道如何才能使其精确:((((
帮助!!:/

您似乎想要暗示精度为1e15

for (double d : new double[]{1.4917951E16, 7.531891E15, 2.9287E13, 3.28478435E17, 6.038E12})
    System.out.printf("%11fE15%n", d/1e15);
印刷品

  14.917951E15
   7.531891E15
   0.029287E15
 328.478435E15
   0.006038E15
0.000000000000001E15
0.0000000001E15
0.00001E15
1E15
100000E15
10000000000E15
如果范围更广,可以使用DecimalFormat

DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(300);
df.setGroupingUsed(false);
for(double d = 1 ; d <= 1e30; d *= 1e5) {
    System.out.println(df.format(d/1e15)+"E15");
}

您似乎希望暗示精度为1e15

for (double d : new double[]{1.4917951E16, 7.531891E15, 2.9287E13, 3.28478435E17, 6.038E12})
    System.out.printf("%11fE15%n", d/1e15);
印刷品

  14.917951E15
   7.531891E15
   0.029287E15
 328.478435E15
   0.006038E15
0.000000000000001E15
0.0000000001E15
0.00001E15
1E15
100000E15
10000000000E15
如果范围更广,可以使用DecimalFormat

DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(300);
df.setGroupingUsed(false);
for(double d = 1 ; d <= 1e30; d *= 1e5) {
    System.out.println(df.format(d/1e15)+"E15");
}

非常感谢!!:-)整个上午都在寻找这个!!:**S2printf是最简单的格式,但可能不是您想要的格式。例如,我怀疑
1
会变成
1e-15e15
;)希望你能了解这个想法,并能使用DecimalFormat或其他格式来满足你的需要。Peter Lawrey你知道有没有使用DecimalFormat的方法吗?我没有找到任何适合这些proupose的方法…printf解决了我的问题,但我想这不是最好的解决方案…对吗?添加了一个DecimalFormat示例。非常感谢!!:-)整个上午都在寻找这个!!:**S2printf是最简单的格式,但可能不是您想要的格式。例如,我怀疑
1
会变成
1e-15e15
;)希望您能了解这个想法,并能使用DecimalFormat或其他格式来满足您的需要。Peter Lawrey您知道使用DecimalFormat的方法吗?我找不到任何适合这些proupose的。。。printf解决了我的问题,但我想这不是最好的解决办法。。对吗?添加了一个DeciamlFormat示例。