In Java, I'm trying to get DecimalFormat to provide an exponent sign. When it's positive, I need a plus sign. From what I read, it seems uninteresting, but for me it always causes an error. I appreciate that there may be other methods to achieve my goal, but I would like to understand why an error occurs in this particular method.
Double result = 123.456;
String sresult;
NumberFormat formatter = new DecimalFormat("0.00000E00");
sresult = formatter.format(result);
System.out.println(sresult);
formatter = new DecimalFormat("0.00000E+00");
sresult = formatter.format(result);
System.out.println(sresult);
Error thrown:
Exception in thread "main" java.lang.IllegalArgumentException:
Malformed exponential pattern "0.00000E + 00"
at java.text.DecimalFormat.applyPattern (Unknown Source)
at java.text.DecimalFormat. (Unknown Source)
at deccheck.main (deccheck.java:13)
I appreciate any insight. Thanks Mark