I'm printing out a matrix, with each element having the same length printed on screen for easier reading.
If I do something like:
System.out.printf("%.16f", x);
then I get different lengths, depending on the preceding (whole) values:
x = 1;
x = 2.345;
x = 10;
x = 1243.5678;
gives the following outputs:
// 1.0000000000000000
// 2.3450000000000000
// 10.0000000000000000
// 1243.5678000000000000
which makes the matrix all messy. How can I limit the entire double - including the decimal and whole number - to a certain length? So, for the previous cases, the outputs would be:
// 1.0000000000000000
// 2.3450000000000000
// 10.000000000000000
// 1243.5678000000000
Edit #1
I don't want to just pad with zeros. Leading zeros are unattractive and can cause misreads. And even though I have %.16f
right now, I may use less precision, and each digit will be significant (and non-zero).