Created
March 31, 2019 10:51
-
-
Save lejon/2de9c0a5425faf2b0000d822f026c7ad to your computer and use it in GitHub Desktop.
Prints a double array in scientific notation with the same number of digits per index.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String toRoundedString(double[] a) { | |
if (a == null) | |
return "null"; | |
int iMax = a.length - 1; | |
if (iMax == -1) | |
return "[]"; | |
StringBuilder b = new StringBuilder(); | |
b.append('['); | |
for (int i = 0; ; i++) { | |
DecimalFormat df = new DecimalFormat("0.00000E0"); | |
String formatted = df.format(a[i]); | |
b.append(formatted); | |
if (i == iMax) | |
return b.append(']').toString(); | |
b.append(", "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment