Sharkysoft home

lava.text
Class NumberFormatter

java.lang.Object
  |
  +--lava.text.StringJustifier
        |
        +--lava.text.NumberFormatter
Direct Known Subclasses:
IntegerFormatter, RealFormatter

public abstract class NumberFormatter
extends StringJustifier

A NumberFormatter 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.

Since applications which must 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.

This is an abstract class. Consult the documentation for subclasses lava.math.IntegerFormatter and lava.math.RealFormatter for examples on how this class is used.

Formatting parameters can be updated at any time, and doing so will change the way text is formatted afterwards. For a detailed description of user-controllable parameters, consult the documentation below.

See Also:
IntegerFormatter, RealFormatter

Field Summary
 java.lang.String neg_prefix
          Prefix for negative numbers.
 java.lang.String neg_suffix
          Suffix for negative numbers.
 java.lang.String pos_prefix
          Prefix for positive numbers.
 java.lang.String pos_suffix
          Suffix for positive numbers.
 int radix
          Radix of the numbers to format.
 int sig_digits
          Number of significant digits to display in the output.
 boolean uppercase
          Indicates whether uppercase digits will be used.
 java.lang.String zero_prefix
          Prefix when number is zero.
 java.lang.String zero_suffix
          Suffix when number is zero.
 
Fields inherited from class lava.text.StringJustifier
cropping, field_width, justification, pad_char
 
Constructor Summary
protected NumberFormatter()
          Initializes a new NumberFormatter with default settings.
 
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

radix

public int radix
Radix of the numbers to format. For example, setting radix to 16 results in hexadecimal output. Default value: 10.

uppercase

public boolean uppercase
Indicates whether uppercase digits will be used. This variable is only applicable when radix > 10. Default value: false.

sig_digits

public int sig_digits
Number of significant digits to display in the output. The number will be rounded if necessary. Setting this value to 0 indicates that all digits are to be considered significant. This constraint may conflict with the max_right_digits constraint in RealFormatter. Default value: 0.

pos_prefix

public java.lang.String pos_prefix
Prefix for positive numbers. Default value: "".

pos_suffix

public java.lang.String pos_suffix
Suffix for positive numbers. Default value: "".

zero_prefix

public java.lang.String zero_prefix
Prefix when number is zero. Default value: "".

zero_suffix

public java.lang.String zero_suffix
Suffix when number is zero. Default value: "".

neg_prefix

public java.lang.String neg_prefix
Prefix for negative numbers. Default value: "-".

neg_suffix

public java.lang.String neg_suffix
Suffix for negative numbers. Default value: "-".
Constructor Detail

NumberFormatter

protected NumberFormatter()
Initializes a new NumberFormatter with default settings.

Sharkysoft home