|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.text.StringJustifier | +--lava.text.NumberFormatter | +--lava.text.IntegerFormatter
An IntegerFormatter
formats numbers according to criteria selected by the user. The user can control various formatting parameters, such as field width, justification style (left-align, right-align, center, etc.), padding characters, etc. Both signed and unsigned (yes!) integer types are support.
Since applications which format numbers frequently format more than one number with the same style, this class is designed to "remember" selected formatting parameters so that they can be reused with each format call. This approach reduces the amount of parameters which must be passed during each format call and results in more efficient execution.
Example: Output the contents of an integer array vals, one integer per line, right-justified in a 25-character-wide field. Round each integer to 3 significant digits.
int[] vals = {2000, 34, 32768}; IntegerFormatter formatter = new IntegerFormatter (); formatter . field_width = 25; formatter . cropping = JUSTIFY.RIGHT; formatter . sig_digits = 3; for (int i = 0; i < vals . length; ++ i) System.out . println (formatter . format (vals [i])); This produces the following output:
2000 34 32800
Formatting parameters can be updated at any time, and doing so will change the way text is formatted afterwards. For a detailed description of all user-controllable parameters, see the documentation below and in the superclass.
Field Summary | |
int |
min_digits
Minimum number of digits to display in output. |
char |
pad_digit
Pad digit to use when extra digits are required by the min_digits parameter. |
Fields inherited from class lava.text.NumberFormatter |
neg_prefix,
neg_suffix,
pos_prefix,
pos_suffix,
radix,
sig_digits,
uppercase,
zero_prefix,
zero_suffix |
Fields inherited from class lava.text.StringJustifier |
cropping,
field_width,
justification,
pad_char |
Constructor Summary | |
IntegerFormatter()
Initializes a new IntegerFormatter with default settings. |
Method Summary | |
java.lang.String |
format(java.math.BigInteger value)
Formats an integer according to the currently selected criteria. |
java.lang.String |
format(int value)
Formats an integer according to currently selected criteria. |
java.lang.String |
format(long value)
Formats an integer according to currently selected criteria. |
java.lang.String |
formatUnsigned(byte value)
Formats an unsigned integer according to currently selected criteria. |
java.lang.String |
formatUnsigned(int value)
Formats an unsigned integer according to currently selected criteria. |
java.lang.String |
formatUnsigned(long value)
Formats an unsigned integer according to currently selected criteria. |
java.lang.String |
formatUnsigned(short value)
Formats an unsigned integer according to currently selected criteria. |
Methods inherited from class lava.text.StringJustifier |
format,
format,
toString |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public char pad_digit
min_digits
parameter. Default value: '0'.public int min_digits
Constructor Detail |
public IntegerFormatter()
Method Detail |
public java.lang.String format(java.math.BigInteger value)
public final java.lang.String format(long value)
public final java.lang.String format(int value)
public final java.lang.String formatUnsigned(long value)
public final java.lang.String formatUnsigned(int value)
public final java.lang.String formatUnsigned(short value)
public final java.lang.String formatUnsigned(byte value)
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |