The EasyFormat class

EasyFormat
EasyFormat examples.
Example code: System.out.println(EasyFormat.format(x, 10, 2)
+ " " + EasyFormat.format(y, 12, 4)

Even though Java's relatively new class "DecimalFormat" is a major help, it is often difficult to align columns in Java output. EasyFormat is intended to make column alignment and other formatting easy.

The output from the demo program shows a number of possibilities.

The following formatting functions return a string:
format(double, numDec)
format(double, width, numDec)
format(String, width)
format(int, width)
format(boolean, width)
format(double, pattern)

  (where the String patterns are defined in the Javadocs for Decimal Format)

In addition there is one function that returns a decmal which was inspired by Excel.
roundTo(double, numDec)

The functions are public static, so a typical use would be:
EasyFormat.format(x, 2)

You can down load the zip file to get all the files in the package. It includes the Java source, class, and jar files together with this file and the image on it.