Real.java
v1.13

ral
Class Real.NumberFormat

java.lang.Object
  extended by ral.Real.NumberFormat
Enclosing class:
Real

public static class Real.NumberFormat
extends Object

The number format used to convert Real values to String using Real.toString(). The default number format uses base-10, maximum precision, removal of trailing zeros and '.' as radix point.

Note that the fields of NumberFormat are not protected in any way, the user is responsible for setting the correct values to get a correct result.


Field Summary
 int align
          The alignment of the output string within a field of maxwidth characters.
static int ALIGN_CENTER
          Center alignment
static int ALIGN_LEFT
          Left alignment
static int ALIGN_NONE
          No alignment
static int ALIGN_RIGHT
          Right alignment
 int base
          The number base of the conversion.
 int fse
          The special output formats FIX, SCI or ENG are enabled with this field.
static int FSE_ENG
          ENG output format
static int FSE_FIX
          FIX output format
static int FSE_NONE
          Normal output format
static int FSE_SCI
          SCI output format
 int maxwidth
          Maximum width of the converted string.
 char point
          The character used as the radix point.
 int precision
          The precision, or number of digits after the radix point in the converted string when using the FIX, SCI or ENG format (see fse).
 boolean removePoint
          Set to true to remove the radix point if this is the last character in the converted string.
 char thousand
          The character used as the thousands separator.
 
Constructor Summary
Real.NumberFormat()
           
 
Method Summary
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

public int base
The number base of the conversion. The default value is 10, valid options are 2, 8, 10 and 16. See Real.and() for an explanation of the interpretation of a Real in base 2, 8 and 16.

Negative numbers output in base-2, base-8 and base-16 are shown in two's complement form. This form guarantees that a negative number starts with at least one digit that is the maximum digit for that base, i.e. '1', '7', and 'F', respectively. A positive number is guaranteed to start with at least one '0'. Both positive and negative numbers are extended to the left using this digit, until maxwidth is reached.


maxwidth

public int maxwidth
Maximum width of the converted string. The default value is 30. If the conversion of a Real with a given precision would produce a string wider than maxwidth, precision is reduced until the number fits within the given width. If maxwidth is too small to hold the number with its sign, exponent and a precision of 1 digit, the string may become wider than maxwidth.

If align is set to anything but ALIGN_NONE and the converted string is shorter than maxwidth, the resulting string is padded with spaces to the specified width according to the alignment.


precision

public int precision
The precision, or number of digits after the radix point in the converted string when using the FIX, SCI or ENG format (see fse). The default value is 16, valid values are 0-16 for base-10 and base-16 conversion, 0-21 for base-8 conversion, and 0-63 for base-2 conversion.

The precision may be reduced to make the number fit within maxwidth. The precision is also reduced if it is set higher than the actual numbers of significant digits in a Real. When fse is set to FSE_NONE, i.e. "normal" output, the precision is always at maximum, but trailing zeros are removed.


fse

public int fse
The special output formats FIX, SCI or ENG are enabled with this field. The default value is FSE_NONE. Valid options are listed below.

Numbers are output in one of two main forms, according to this setting. The normal form has an optional sign, one or more digits before the radix point, and zero or more digits after the radix point, for example like this:
   3.14159
The exponent form is like the normal form, followed by an exponent marker 'e', an optional sign and one or more exponent digits, for example like this:
   -3.4753e-13

FSE_NONE
Normal output. Numbers are output with maximum precision, trailing zeros are removed. The format is changed to exponent form if the number is larger than the number of significant digits allows, or if the resulting string would exceed maxwidth without the exponent form.
FSE_FIX
Like normal output, but the numbers are output with a fixed number of digits after the radix point, according to precision. Trailing zeros are not removed.
FSE_SCI
The numbers are always output in the exponent form, with one digit before the radix point, and a fixed number of digits after the radix point, according to precision. Trailing zeros are not removed.
FSE_ENG
Like the SCI format, but the output shows one to three digits before the radix point, so that the exponent is always divisible by 3.


point

public char point
The character used as the radix point. The default value is '.'. Theoretcally any character that does not otherwise occur in the output can be used, such as ','.

Note that setting this to anything but '.' and ',' is not supported by any conversion method from String back to Real.


removePoint

public boolean removePoint
Set to true to remove the radix point if this is the last character in the converted string. This is the default.


thousand

public char thousand
The character used as the thousands separator. The default value is the character code 0, which disables thousands-separation. Theoretcally any character that does not otherwise occur in the output can be used, such as ',' or ' '.

When thousand!=0, this character is inserted between every 3rd digit to the left of the radix point in base-10 conversion. In base-16 conversion, the separator is inserted between every 4th digit, and in base-2 conversion the separator is inserted between every 8th digit. In base-8 conversion, no separator is ever inserted.

Note that tousands separators are not supported by any conversion method from String back to Real, so use of a thousands separator is meant only for the presentation of numbers.


align

public int align
The alignment of the output string within a field of maxwidth characters. The default value is ALIGN_NONE. Valid options are defined as follows:

ALIGN_NONE
The resulting string is not padded with spaces.
ALIGN_LEFT
The resulting string is padded with spaces on the right side until a width of maxwidth is reached, making the number left-aligned within the field.
ALIGN_RIGHT
The resulting string is padded with spaces on the left side until a width of maxwidth is reached, making the number right-aligned within the field.
ALIGN_CENTER
The resulting string is padded with spaces on both sides until a width of maxwidth is reached, making the number center-aligned within the field.


FSE_NONE

public static final int FSE_NONE
Normal output format

See Also:
Constant Field Values

FSE_FIX

public static final int FSE_FIX
FIX output format

See Also:
Constant Field Values

FSE_SCI

public static final int FSE_SCI
SCI output format

See Also:
Constant Field Values

FSE_ENG

public static final int FSE_ENG
ENG output format

See Also:
Constant Field Values

ALIGN_NONE

public static final int ALIGN_NONE
No alignment

See Also:
Constant Field Values

ALIGN_LEFT

public static final int ALIGN_LEFT
Left alignment

See Also:
Constant Field Values

ALIGN_RIGHT

public static final int ALIGN_RIGHT
Right alignment

See Also:
Constant Field Values

ALIGN_CENTER

public static final int ALIGN_CENTER
Center alignment

See Also:
Constant Field Values
Constructor Detail

Real.NumberFormat

public Real.NumberFormat()

Real.java
v1.13

Copyright 2003-2009 Roar Lauritzsen