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


Constructor Index

 o OutFmt()

Method Index

 o fmt(double)
return double n as a String, using number of decimal places currently set (default 2, changed w/ setDecimalPlaces())
 o fmt(int)
return int n as a String
 o LJust(String, int)
return str as a String, LEFT-justified in col total columns; will not truncate Strings whose length is > col.
 o RJust(String, int)
return str as a String, RIGHT-justified in col total columns; will not truncate Strings whose length is > col.
 o setDecimalPlaces(int)
set the number of decimal places to be printed, w/ trailing 0's in subsequent printing operations.

Constructors

 o OutFmt
 public OutFmt()

Methods

 o 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
 o fmt
 public static String fmt(int n)
return int n as a String

Parameters:
n; - the int to be formatted
 o 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
 o 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.

 o 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