I have some double numbers that are outputted with this format:
Format.String("%1.4e",doubleNumber);
The result is 1.123456e+03. How can I set the number of cipher of exponent for getting this format:
1.123456e+003
I would have always 3 cipher after e symbol.
Thank you
UPDATE 1:
I have partially resolved:
DecimalFormat formatter = new DecimalFormat("0.000000E000");
System.out.println( formatter.format(doubleNumber) );
Now the number has always the format
1.123456e0xx
or
1.123456e-0xx
But it's not all resolved. I would have always printed the sign:
1.123456e+0xx or 1.123456e-0xx
解决方案
Thank you @TDG
private String formatter(double number){
DecimalFormat formatter = new DecimalFormat("0.000000E000");
String fnumber = formatter.format(number);
if (!fnumber.contains("E-")) { //don't blast a negative sign
fnumber = fnumber.replace("E", "E+");
}
return fnumber;
}