All Packages Class Hierarchy This Package Previous Next Index
Class utils.OutFmt
java.lang.Object
|
+----utils.OutFmt
- public class OutFmt
- extends Object
provide basic number formatting for printing:
field widths, leading 0's, etc.
USAGE: to format int n in cols columns:
OutFmt.RJust (OutFmt.fmt(n), cols); // or LJust()
to format double n in cols total columns (including decimal
point), with decPlcs digits to the right of the decimal point:
OutFmt.setDecimalPlaces(decPlcs); // if current setting n.g.
OutFmt.RJust(OutFmt.fmt(n), cols);
NOTE: RJust(), LJust() work on arbitrary Strings, not just numeric Strs.
Default format is: two decimal places, with trailing 0's,
minimum number of integer places, including - sign
-
OutFmt()
-
-
fmt(double)
- return double n as a String, using number of decimal places
currently set (default 2, changed w/ setDecimalPlaces())
-
fmt(int)
- return int n as a String
-
LJust(String, int)
- return str as a String, LEFT-justified in col total columns;
will not truncate Strings whose length is > col.
-
RJust(String, int)
- return str as a String, RIGHT-justified in col total columns;
will not truncate Strings whose length is > col.
-
setDecimalPlaces(int)
- set the number of decimal places to be printed, w/ trailing 0's
in subsequent printing operations.
OutFmt
public OutFmt()
fmt
public static String fmt(double n)
- return double n as a String, using number of decimal places
currently set (default 2, changed w/ setDecimalPlaces())
- Parameters:
- n; - the double to be formatted (ints get promoted to double,
so don't come out like ints.
- See Also:
- setDecimalPlaces
fmt
public static String fmt(int n)
- return int n as a String
- Parameters:
- n; - the int to be formatted
setDecimalPlaces
public static void setDecimalPlaces(int howMany)
- set the number of decimal places to be printed, w/ trailing 0's
in subsequent printing operations. The new format will remain
in force till explicitly changed.
- Parameters:
- howMany: - the number of decimal places to be set
LJust
public static String LJust(String str,
int col)
- return str as a String, LEFT-justified in col total columns;
will not truncate Strings whose length is > col.
RJust
public static String RJust(String str,
int col)
- return str as a String, RIGHT-justified in col total columns;
will not truncate Strings whose length is > col.
All Packages Class Hierarchy This Package Previous Next Index