ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Static Fields | Public Fields | Public Static Methods | Public Methods | Protected Static Fields | Protected Methods | List of all members
NumberFormat Class Reference
Collaboration diagram for NumberFormat:
[legend]

Class Description


Defines various values needed to convert integer and floating point values to string representations and vice versa. In addition, this class provides methods that do such conversions on character array buffers.

Attention
The methods of this class are not intended for the common use. Instead, use interface of classes AString, Substring or Formatter to write and parse numbers, which accept an object of this type as parameters.

Defined Singletons and User-Defined Instances:
Two static singletons of this class are defined which can be used whereve r a number format object is needed as a parameter:

User defined objects default to the 'computational' setting after construction.

Output Formats:
The following conversion formats are supported

Notes on Writing and Parsing Values:

Attention
For decimal output, the width (decMinimumFieldWidth) is a minimum width. This mean, that bigger numbers are written in a higher width. This is not true for binary, hexadecimal and octal output. In these formats, the width is an absolute value. Higher digits of numbers are just not written. The advantage of this is that no masking is needed when just the lower part of an integer number should be written. However, numbers might of-course change when cut and parsed back later!

All of the integer formats have in common that the output width given is including optional grouping characters. For example if a width of 5 was given for decimal output, the value 12 would be written "0,012", hence 4 digits plus the grouping character. If grouping was disabled, the output became "00012", hence one digit more but the same width. In contrast to that, any sign that is written is not counted in the width.

When parsing values, grouping characters are ignored at any position within the digits, except of the start. The same is true for whitespace characters as defined in whitespaces. When this field is nulled or empty, then white spaces are not ignored. This might be helpful in some cases where occurrence of white space characters should indicate an error (or something else) when parsing. Otherwise, the characters defined in this field are ignored at two places: at the beginning of a parsing operation and after a sign character was read.

When parsing fails, a value of 0 (respectively 0.0) is returned. User-friendly classes that use the interface of this type will detect such failure through the output parameter of the parsing methods, which indicates the end of the number found.

For each of the four integer formats, decimal, binary, hexadecimal and octal, dedicated parsing methods exist. Those do not accept literal prefix identifiers as defined in fields binLiteralPrefix, hexLiteralPrefix and octLiteralPrefix. Those are identified by method parseInt, which aggregates the other four parsing methods.
There is no corresponding method defined that writes the literal prefix. When writing binary, hexadecimal or octal values, such prefixes have to be prepended 'manually'.

ALib for Java Specifics:

Public Static Fields

static final long bitsInfNeg = Double.doubleToRawLongBits( Double.NEGATIVE_INFINITY )
 
static final long bitsInfPos = Double.doubleToRawLongBits( Double.POSITIVE_INFINITY)
 
static final long bitsNaN = Double.doubleToRawLongBits( Double.NaN )
 
static NumberFormat computational =new NumberFormat()
 
static NumberFormat global =new NumberFormat()
 
static final long signMask
 

Public Fields

char binByteGroupChar
 
int binFieldWidth
 
com.aworx.lib.strings.AString binLiteralPrefix
 
char binNibbleGroupChar
 
char binWord32GroupChar
 
char binWordGroupChar
 
char decimalPointChar
 
int decMinimumFieldWidth
 
String exponentSeparator
 
boolean forceDecimalPoint
 
boolean forceScientific
 
int fractionalPartWidth
 
char hexByteGroupChar
 
int hexFieldWidth
 
com.aworx.lib.strings.AString hexLiteralPrefix
 
boolean hexLowerCase
 
char hexWord32GroupChar
 
char hexWordGroupChar
 
String INFLiteral
 
int integralPartMinimumWidth
 
char leadingGroupCharReplacement
 
String NANLiteral
 
int octFieldWidth
 
char octGroupChar
 
com.aworx.lib.strings.AString octLiteralPrefix
 
boolean omitTrailingFractionalZeros
 
char plusSign
 
boolean readGroupChars
 
char thousandsGroupChar
 
char[] whitespaces
 
boolean writeExponentPlusSign
 
boolean writeGroupChars
 

Public Static Methods

static long parseDecDigits (char[] buffer, int idx, int maxIdx, int[] newIdx)
 

Public Methods

 NumberFormat ()
 
long parseBin (char[] buffer, int idx, int maxIdx, int[] newIdx)
 
long parseDec (char[] buffer, int idx, int maxIdx, int[] newIdx)
 
double parseFloat (char[] buffer, int idx, int maxIdx, int[] newIdx)
 
long parseHex (char[] buffer, int idx, int maxIdx, int[] newIdx)
 
long parseInt (char[] buffer, int idx, int maxIdx, int[] newIdx)
 
long parseOct (char[] buffer, int idx, int maxIdx, int[] newIdx)
 
void set ()
 
void set (NumberFormat other)
 
void setComputational ()
 
void setFromLocale ()
 
int writeBin (long value, char[] buffer, int idx, int overrideWidth)
 
int writeDecSigned (long value, char[] buffer, int idx, int overrideWidth)
 
int writeDecUnsigned (long value, char[] buffer, int idx, int overrideWidth)
 
int writeFloat (double value, char[] buffer, int idx, int overrideWidth)
 
int writeHex (long value, char[] buffer, int idx, int overrideWidth)
 
int writeOct (long value, char[] buffer, int idx, int overrideWidth)
 

Protected Static Fields

static int[] dummyNewIdx = new int[1]
 
static char[] longMinValue = "9#223#372#036#854#775#808".toCharArray()
 
static long pow10_0to18 []
 

Protected Methods

int writeDecUnsignedImpl (long value, char[] buffer, int idx, int width)
 

Constructor & Destructor Documentation

◆ NumberFormat()


Constructor. Invokes setComputational to reset all fields to their default values.

Member Function Documentation

◆ parseBin()

long parseBin ( char[]  buffer,
int  idx,
int  maxIdx,
int[]  newIdx 
)

Reads an unsigned integer value in decimal format from the given character array at the given position.
Sign literals '-' or '+' are not accepted and parsing will fail if found. Whitespace and grouping characters, as defined in fields whitespaces, binNibbleGroupChar, binByteGroupChar, binWordGroupChar and binWord32GroupChar will be ignored, regardless on their position between digits. To suppress the parsing of group characters, set the fields to '\0'. To suppress whitespace consumption, set field whitespaces to null or empty char[].

Note
As Java does not support unsigned integer types, the value will be negative if bit number 64 is set.
Parameters
bufferThe character array to read the value from.
idxThe start point for parsing within buffer.
maxIdxThe maximum index to look at. Must be smaller than the buffers' length.
[out]newIdxOptional output parameter (in array position 0) that Will be set to point behind the last character consumed. If parsing fails, it will be set to the value of parameter idx which indicates that no parsable number was found.
Returns
The parsed value. In addition, the parameter newIdx is set to point to the first character behind any found number.

◆ parseDec()

long parseDec ( char[]  buffer,
int  idx,
int  maxIdx,
int[]  newIdx 
)

Reads an unsigned integer value in decimal format from the given character array at the given position.
Sign literals '-' or '+' are not accepted and parsing will fail if found. Whitespace and grouping characters, as defined in fields whitespaces and thousandsGroupChar will be ignored, regardless on their position between digits. To suppress the parsing of group characters set, field thousandsGroupChar to '\0'. To suppress whitespace consumption before reading the value, set field whitespaces to nulled or empty string.

Note
As Java does not support unsigned integer types, the value to read is limited to Long.MAX_VALUE in this implementation of ALib.
Parameters
bufferThe character array to read the value from.
idxThe start point for parsing within buffer.
maxIdxThe maximum index to look at. Must be smaller than the buffers' length.
[out]newIdxOptional output parameter (in array position 0) that Will be set to point behind the last character consumed. If parsing fails, it will be set to the value of parameter idx which indicates that no parsable number was found.
Returns
The parsed value. In addition, the parameter newIdx is set to point to the first character behind any found number.

◆ parseDecDigits()

static long parseDecDigits ( char[]  buffer,
int  idx,
int  maxIdx,
int[]  newIdx 
)
static

Static method to read digits '0' to '9' into a positive integer value.

Parameters
bufferThe character array to read the value from.
idxThe start point for parsing within buffer.
maxIdxThe maximum index to look at. Must be smaller than the buffers' length.
[out]newIdxOptional output parameter (in array position 0) that Will be set to point behind the last character consumed. If parsing fails, it will be set to the value of parameter idx which indicates that no parsable number was found.
Returns
The parsed value. In addition, the parameter newIdx is set to point to the first character behind any found number.

◆ parseFloat()

double parseFloat ( char[]  buffer,
int  idx,
int  maxIdx,
int[]  newIdx 
)

Reads an unsigned integer value in decimal format from the given character array at the given position.
Sign literals '-' or '+' are not accepted and parsing will fail if found. and parsing will fail if found.

Parameters
bufferThe character array to read the value from.
idxThe start index from where the float value is tried to be parsed.
maxIdxThe maximum index to look at. Must be smaller than the buffer length.
newIdxOptional output variable (in array position 0) that will point to the first character after the integer number that was parsed. If parsing fails, it will be set to the value of parameter idx. Therefore, this parameter can be used to check if a value was found.
Returns
The parsed value. In addition, on success, the output parameter newIdx is set to point to the first character behind any found float number.

◆ parseHex()

long parseHex ( char[]  buffer,
int  idx,
int  maxIdx,
int[]  newIdx 
)

Reads an unsigned integer value in decimal format from the given character array at the given position.
Sign literals '-' or '+' are not accepted and parsing will fail if found. Whitespace and grouping characters, as defined in fields whitespaces, hexByteGroupChar, hexWordGroupChar and hexWord32GroupChar will be ignored, regardless on their position between digits. To suppress the parsing of group characters, set the fields to '\0'. To suppress whitespace consumption, set field whitespaces to null or empty char[].

Note
As Java does not support unsigned integer types, the value will be negative if bit number 64 is set.
Parameters
bufferThe character array to read the value from.
idxThe start point for parsing within buffer.
maxIdxThe maximum index to look at. Must be smaller than the buffers' length.
[out]newIdxOptional output parameter (in array position 0) that Will be set to point behind the last character consumed. If parsing fails, it will be set to the value of parameter idx which indicates that no parsable number was found.
Returns
The parsed value. In addition, the parameter newIdx is set to point to the first character behind any found number.

◆ parseInt()

long parseInt ( char[]  buffer,
int  idx,
int  maxIdx,
int[]  newIdx 
)

Parses signed integer numbers, optionally in binary, hexadecimal or octal format.

Leading characters defined in whitespaces are ignored. An optional sign character '+' or '-' is parsed. If found, again whitespace characters may follow behind such sign and are ignored.

Then, the method detects any literal prefixes as defined in fields binLiteralPrefix, hexLiteralPrefix and octLiteralPrefix (usually 0b, 0x and 0o) and invokes one of the methods parseDec, parseBin, parseHex or parseOct.

Parameters
bufferThe character array to read the value from.
idxThe start point for parsing within buffer.
maxIdxThe maximum index to look at. Must be smaller than the buffers' length.
[out]newIdxOptional output parameter (in array position 0) that Will be set to point behind the last character consumed. If parsing fails, it will be set to the value of parameter idx which indicates that no parsable number was found.
Returns
The parsed value. In addition, the parameter newIdx is set to point to the first character behind any found number.

◆ parseOct()

long parseOct ( char[]  buffer,
int  idx,
int  maxIdx,
int[]  newIdx 
)

Reads an unsigned integer value in decimal format from the given character array at the given position.
Sign literals '-' or '+' are not accepted and parsing will fail if found. Whitespace and grouping characters, as defined in fields whitespaces and octGroupChar will be ignored, regardless on their position between digits. To suppress the parsing of group characters, set the field to '\0'. To suppress whitespace consumption, set field whitespaces to null or empty char[].

Note
As Java does not support unsigned integer types, the value will be negative if bit number 64 is set.
Parameters
bufferThe character array to read the value from.
idxThe start point for parsing within buffer.
maxIdxThe maximum index to look at. Must be smaller than the buffers' length.
[out]newIdxOptional output parameter (in array position 0) that Will be set to point behind the last character consumed. If parsing fails, it will be set to the value of parameter idx which indicates that no parsable number was found.
Returns
The parsed value. In addition, the parameter newIdx is set to point to the first character behind any found number.

◆ set() [1/2]

void set ( )

Overloaded version of set(NumberFormat) providing default parameter value null.

◆ set() [2/2]

void set ( NumberFormat  other)

Copies all fields (settings) from the given object. If no object is provided, values of the static singleton found in field global are copied

Parameters
otherThe NumberFormat object to copy the values from. Defaults to null, which chooses the global singleton.

◆ setComputational()

void setComputational ( )

Resets the object to its default values. This method is called in the constructor.

Decimal point character and grouping characters are set as follows:

Field
Value
decimalPointChar .
thousandsGroupChar ,
binNibbleGroupChar '
binByteGroupChar -
binWordGroupChar ' ' (space)
binWord32GroupChar #
hexWordGroupChar '
hexWord32GroupChar '
hexByteGroupChar 0 (none)
octGroupChar '

The literal attributes are set as follows:

Field
Value
exponentSeparator "E"
INFLiteral "INF"
NANLiteral "NAN"
binLiteralPrefix "0b"
hexLiteralPrefix "0x"
octLiteralPrefix "0o"

All width-attributes are reset to "automatic mode", -1. The attributes are integralPartMinimumWidth, fractionalPartWidth, decMinimumFieldWidth, binFieldWidth, hexFieldWidth and octFieldWidth.

Finally, the following further fields are reset to their default values:

Field
Value
writeGroupChars false
forceScientific false
forceDecimalPoint true
plusSign none (0)
writeExponentPlusSign false
omitTrailingFractionalZeros false
hexLowerCase false
whitespaces DEFAULT_WHITESPACES
Note
With static object NumberFormat.computational, there is a global singleton existing which can be used but must not be changed.

◆ setFromLocale()

void setFromLocale ( )

Sets the field decimalPointChar and thousandsGroupChar to reflect the current system locales' setting. No other values are changed.

Note
Static (global) object NumberFormat.global, implements an instance which has the right locale set (provided that ALIB.init was duly invoked by the process). Otherwise, this method might be used to initialize a custom object with default values to afterwards make some specific changes.

◆ writeBin()

int writeBin ( long  value,
char[]  buffer,
int  idx,
int  overrideWidth 
)

Converts the given long value to a string representation in binary format.
Negative numbers have to be converted to positive values when invoking this method. the digits and optional grouping characters. The method does not check any overflow within the given character buffer.

The maximum number of digits written is 64. In addition, grouping characters may be written according the settings of fields writeGroupChars, binNibbleGroupChar, binByteGroupChar, binWordGroupChar, binWord32GroupChar and leadingGroupCharReplacement.

The minimum width of the output is taken from field binFieldWidth unless overwritten by parameter overrideWidth. If the width is greater than digits found in value, '0' digits are prepended. The width is taking group characters into account.

Attention
If the value is greater than can be represented by the output width, these greater digits are cut. This is true for this method as well as writeHex and writeOct. The rational behind this is that this way, larger numbers do not need to be masked before writing. (In other words: it is assumed that there is a reason for providing the width).

The literal prefix found in field binLiteralPrefix is not written. The field is only used for detecting formats with method parseInt.

Parameters
valueThe value to write.
bufferThe character array to write the value to. Needs to be long enough (after idx) to carry the string written.
idxThe index within buffer to start writing.
overrideWidthMay be used to override value of field binFieldWidth. Defaults to 0, which denotes to use the fields' value.
Returns
The index pointing to behind the last character written in buffer.

◆ writeDecSigned()

int writeDecSigned ( long  value,
char[]  buffer,
int  idx,
int  overrideWidth 
)

Converts the given long value to a string representation into a signed decimal format.
For negative numbers, '-' is written, the sign of positive numbers (if any) depends on field plusSign. After that, the value is converted to positive and writeDecUnsigned is invoked.

Parameters
valueThe value to write.
bufferThe character array to write the value to. Needs to be long enough (after idx) to carry the string written.
idxThe index within buffer to start writing.
overrideWidthMay be used to override value of field decMinimumFieldWidth. Defaults to 0, which denotes to use the fields' value.
Returns
The index pointing to behind the last character written in buffer.

◆ writeDecUnsigned()

int writeDecUnsigned ( long  value,
char[]  buffer,
int  idx,
int  overrideWidth 
)

Converts the given long value to a string representation in decimal format.
Negative numbers have to be converted to positive values when invoking this method. the digits and optional grouping characters. The method does not check any overflow within the given character buffer.

The maximum number of digits written is 19. In addition, grouping characters may be written according the settings of fields writeGroupChars, thousandsGroupChar and leadingGroupCharReplacement.

The minimum width of the output is taken from field decMinimumFieldWidth unless overwritten by parameter overrideWidth. If the width is greater than the sum of digits and grouping characters found in value, then '0' digits are prepended between the sign and the number.

Parameters
valueThe value to write.
bufferThe character array to write the value to. Needs to be long enough (after idx) to carry the string written.
idxThe index within buffer to start writing.
overrideWidthMay be used to override value of field decMinimumFieldWidth. Defaults to 0, which denotes to use the fields' value.
Returns
The index pointing to behind the last character written in buffer.

◆ writeDecUnsignedImpl()

int writeDecUnsignedImpl ( long  value,
char[]  buffer,
int  idx,
int  width 
)
protected

Implementation used by writeDecSigned and writeDecUnsigned.

Parameters
valueThe value to write.
bufferThe character array to write the value to. Needs to be long enough (after idx) to carry the string written.
idxThe index within buffer to start writing.
widthThe overall minimum width to write.
Returns
The index pointing to behind the last character written in buffer.

◆ writeFloat()

int writeFloat ( double  value,
char[]  buffer,
int  idx,
int  overrideWidth 
)

Writes the given double value as string representation.

Converts the given long value to a string representation.
Negative numbers have to be converted to positive values when invoking this method. the digits and optional grouping characters. The method does not check any overflow within the given character buffer.

Grouping characters are written according the settings of fields writeGroupChars, thousandsGroupChar and leadingGroupCharReplacement.

The minimum width of the the integral part of the output is taken from field integralPartMinimumWidth unless overwritten by parameter overrideWidth. If the width is greater than integral digits found in value, '0' digits are prepended. The width is taking group characters into account.

If field fractionalPartWidth as well as the width of the integral part ( provided or set) equals -1 the method may choose scientific notation. This is done, when for numbers smaller than 10E-4 or larger than 10E+6.

If the given value is not a number, NANLiteral is written. If infinite, INFLiteral.

The output format is dependent on various further settings provided in the fields of this class. Those are decimalPointChar, exponentSeparator, forceDecimalPoint, writeExponentPlusSign and forceScientific

Parameters
valueThe value to write.
bufferThe character array to write the value to. Needs to be long enough (after idx) to carry the string written.
idxThe index within buffer to start writing.
overrideWidthMay be used to override value of field integralPartMinimumWidth. Defaults to 0, which denotes to use the fields' value.
Returns
The index pointing to behind the last character written in buffer.

◆ writeHex()

int writeHex ( long  value,
char[]  buffer,
int  idx,
int  overrideWidth 
)

Converts the given long value to a string representation in hexadecimal format.
Negative numbers have to be converted to positive values when invoking this method. the digits and optional grouping characters. The method does not check any overflow within the given character buffer.

The maximum number of digits written is 16. In addition, grouping characters may be written according the settings of fields writeGroupChars, hexByteGroupChar, hexWordGroupChar, hexWord32GroupChar and leadingGroupCharReplacement.

The minimum width of the output is taken from field hexFieldWidth unless overwritten by parameter overrideWidth. If the width is greater than digits found in value, '0' digits are prepended. The width is taking group characters into account.

Attention
If the value is greater than can be represented by the output width, these greater digits are cut. This is true for this method as well as writeBin and writeOct. The rational behind this is that this way, larger numbers do not need to be masked before writing. (In other words: it is assumed that there is a reason for providing the width).

The literal prefix found in field hexLiteralPrefix is not written. The field is only used for detecting formats with method parseInt.

Parameters
valueThe value to write.
bufferThe character array to write the value to. Needs to be long enough (after idx) to carry the string written.
idxThe index within buffer to start writing.
overrideWidthMay be used to override value of field hexFieldWidth. Defaults to 0, which denotes to use the fields' value.
Returns
The index pointing to behind the last character written in buffer.

◆ writeOct()

int writeOct ( long  value,
char[]  buffer,
int  idx,
int  overrideWidth 
)

Converts the given long value to a string representation in octal format.
Negative numbers have to be converted to positive values when invoking this method. the digits and optional grouping characters. The method does not check any overflow within the given character buffer.

The maximum number of digits written is 64. In addition, grouping characters may be written according the settings of fields writeGroupChars, octGroupChar and leadingGroupCharReplacement.

The minimum width of the output is taken from field octFieldWidth unless overwritten by parameter overrideWidth. If the width is greater than digits found in value, '0' digits are prepended. The width is taking group characters into account.

Attention
If the value is greater than can be represented by the output width, these greater digits are cut. This is true for this method as well as writeBin and writeHex. The rational behind this is that this way, larger numbers do not need to be masked before writing. (In other words: it is assumed that there is a reason for providing the width).

The literal prefix found in field octLiteralPrefix is not written. The field is only used for detecting formats with method parseInt.

Parameters
valueThe value to write.
bufferThe character array to write the value to. Needs to be long enough (after idx) to carry the string written.
idxThe index within buffer to start writing.
overrideWidthMay be used to override value of field octFieldWidth. Defaults to 0, which denotes to use the fields' value.
Returns
The index pointing to behind the last character written in buffer.

Member Data Documentation

◆ binByteGroupChar

char binByteGroupChar

Defines the separator character for bytes of binary numbers. Defaults to '\0' what chooses binNibbleGroupChar.

◆ binFieldWidth

int binFieldWidth

Defines the digits written when writing binary values. If the value has less digits, then leading '0' digits are added. If it has more, than those digits are NOT written (!).
The default value and minimum value is -1, which writes as many bits as necessary.

◆ binLiteralPrefix

Used by method parseInt to detect binary format of integer values. If nulled, no binary format is detected. Methods of this class are not writing the prefix. If desired, this has performed explicitly ("manually") prior to invoking a writing method of this class.
Defaults to "0b".

◆ binNibbleGroupChar

char binNibbleGroupChar

Defines the separator character for nibbles (4 bits) of binary numbers. Defaults to '\0' what disables reading and writing of nibble group characters.

◆ binWord32GroupChar

char binWord32GroupChar

Defines the separator character for 32-bit words of binary numbers. Defaults to '\0' what chooses binWordGroupChar.

◆ binWordGroupChar

char binWordGroupChar

Defines the separator character for 16-bit words of binary numbers. Defaults to '\0' what chooses binByteGroupChar.

◆ bitsInfNeg

final long bitsInfNeg = Double.doubleToRawLongBits( Double.NEGATIVE_INFINITY )
static

Used for float conversion

◆ bitsInfPos

final long bitsInfPos = Double.doubleToRawLongBits( Double.POSITIVE_INFINITY)
static

Used for float conversion

◆ bitsNaN

final long bitsNaN = Double.doubleToRawLongBits( Double.NaN )
static

Used for float conversion

◆ computational

NumberFormat computational =new NumberFormat()
static

A static number format object that may be used to write and parse numbers for 'computational' use, which means, that grouping is switched off and decimal point character is '.'.
Method ALIB.init invokes setComputational on this object. Note that using code that use this field without having invoked ALIB.init may behave wrongly.

Classes providing functionality based on this class, might use this as a default value for parameters of their interface methods.

◆ decimalPointChar

char decimalPointChar

Defines the decimal point character when converting a floating point number to a string representation with method writeFloat. Also, method parseFloat uses the character provided in this field for parsing the character.
The field defaults to '.'. By invoking setFromLocale(), the current locale's setting is determined.

◆ decMinimumFieldWidth

int decMinimumFieldWidth

Defines the minimum digits and grouping symbols written when writing integers in decimal. format. If the value to write has less digits (and grouping symbols), then leading '0' digits (and eventually grouping symbols) are added.
If the value to write has more digits, then this field is ignored. A sign character is not calculated into the writing width. To have negative and positive numbers resulting in the same width, plusSign has to be set to a value unequal to '\0' (usually space character ' ' or '+').

If this field is negative, it is ignored. Defaults to -1.

◆ dummyNewIdx

int [] dummyNewIdx = new int[1]
staticprotected

temporary array used when null is given for 'return value array'.

◆ exponentSeparator

String exponentSeparator

Defines the decimal exponent symbol of string representations of floating point numbers when written or parsed in scientific notation by methods parseFloat and writeFloat.
Method parseFloat accepts characters 'e' and 'E' in addition to the string set in this field.
Defaults to 'E'.

◆ forceDecimalPoint

boolean forceDecimalPoint

If true, the decimal point of floating point values is written, even if the fractional part of the float value is zero. If false, in this case the decimal point is omitted.
Defaults to true.

◆ forceScientific

boolean forceScientific

If true, scientific format is always used.
If false (the default), method writeFloat writes scientific format only if both fields, integralPartMinimumWidth and fractionalPartWidth are evaluating to -1 and only for numbers smaller than 10E-04 or larger than 10E+06.

If one of the fields integralPartMinimumWidth or fractionalPartWidth is set to a positive value, these limits get extended. Method writeFloat in this case keeps non-scientific notation established if possible.

◆ fractionalPartWidth

int fractionalPartWidth

Defines the number of digits written for the fractional part when converting a floating point value into a string. (For integer conversion, see decMinimumFieldWidth.)
If the fractional part of the number provided has less digits then trailing '0' digits are added.
If the fractional part of the number provided has more digits then the fractional part is rounded accordingly.
The maximum value allowed is 15.
The default value is -1, which writes as many digits as available in the provided float variable, with a minimum of 1 digit.

When either this field or field integralPartMinimumWidth is set to a positive value, the limits to switch to scientific notation, which otherwise are fixed 10E-04 and 10E+06, get extended. Method writeFloat in this case keeps non-scientific notation established if possible.

◆ global

NumberFormat global =new NumberFormat()
static

The default static number format object that acts as the default settings of the currently running process.
Method ALIB.init invokes setFromLocale() on this object and switches grouping on.

Classes providing functionality based on this class, might use this as a default value for parameters of their interface methods.

◆ hexByteGroupChar

char hexByteGroupChar

Defines the separator character for bytes of hexadecimal numbers. Defaults to '\0' what disables reading and writing of byte group characters.

◆ hexFieldWidth

int hexFieldWidth

Defines the digits written when writing hexadecimal values. If the value has less digits, then leading '0' digits are added. If it has more, than those digits are NOT written (!).
The default value and minimum value is -1, which writes as many bits as necessary.

◆ hexLiteralPrefix

Used by method parseInt to detect hexadecimal format of integer values. If nulled, no hexadecimal format is detected. Methods of this class are not writing the prefix. If desired, this has performed explicitly ("manually") prior to invoking a writing method of this class.
Defaults to "0x".

◆ hexLowerCase

boolean hexLowerCase

If true, lower case letters 'a' - 'f' are written. Defaults to false, which writes upper case letters 'A' - 'F'.

◆ hexWord32GroupChar

char hexWord32GroupChar

Defines the separator character for 32-bit words of hexadecimal numbers. Defaults to '\0' what chooses hexWordGroupChar.

◆ hexWordGroupChar

char hexWordGroupChar

Defines the separator character for 16-bit words of hexadecimal numbers. Defaults to '\0' what chooses hexByteGroupChar.

◆ INFLiteral

String INFLiteral

Defines what is written and parsed for infinite double values.

◆ integralPartMinimumWidth

int integralPartMinimumWidth

Defines the minimum digits written for the integral part when converting a floating point value into a string.
If the integral part of the number provided has less digits then leading '0' digits are added.
The maximum value allowed is 15.
A value of 0 leads to omitting the '0' before the decimal separator in the case the value is below 1.0 and higher than -1.0
The default value is -1, which writes a minimum of 1 digit.

When either this field or field fractionalPartWidth is set to a positive value, the limits to switch to scientific notation, which otherwise are fixed 10E-04 and 10E+06, get extended. Method writeFloat in this case keeps non-scientific notation established if possible.

◆ leadingGroupCharReplacement

char leadingGroupCharReplacement

This character is written instead of a grouping character in the case that a certain output width is requested but a grouping character would be the first character to write. Writing this character instead, assures the field width be as requested. Defaults to space (' ').

◆ longMinValue

char [] longMinValue = "9#223#372#036#854#775#808".toCharArray()
staticprotected

Special treatment for Long.MIN_VALUE: can not be converted to positive.

◆ NANLiteral

String NANLiteral

Defines what is written and parsed for double values that represent "not a number".

◆ octFieldWidth

int octFieldWidth

Defines the digits written when writing hexadecimal values. If the value has less digits, then leading '0' digits are added. If it has more, than those digits are NOT written (!).
The default value and minimum value is -1, which writes as many bits as necessary.

◆ octGroupChar

char octGroupChar

Defines the separator character for bytes of hexadecimal numbers. Defaults to ', Defaults to '\0' what disables reading and writing of byte group characters.

◆ octLiteralPrefix

Used by method parseInt to detect octal format of integer values. If nulled, no octal format is detected. Methods of this class are not writing the prefix. If desired, this has performed explicitly ("manually") prior to invoking a writing method of this class.
Defaults to "0o".

◆ omitTrailingFractionalZeros

boolean omitTrailingFractionalZeros

If this field is true, then trailing '0' digits in the fractional part of a floating point value are not written, even if a fractionalPartWidth is set. Defaults to false.

◆ plusSign

char plusSign

Determines if positive values are prepended with an explicit character (usually '+') when written using writeFloat or writeDecSigned.
Defaults to 0 which omits the writing. Usual other values are of-course '+', but also ' ' (space) which supports better horizontal alignment of numbers when written in columns. Note that this is not affecting exponent decimals of floating point values. For those, see writeExponentPlusSign

◆ pow10_0to18

long pow10_0to18[]
staticprotected
Initial value:
=
{
1L,
10L,
100L,
1000L,
10000L,
100000L,
1000000L,
10000000L,
100000000L,
1000000000L,
10000000000L,
100000000000L,
1000000000000L,
10000000000000L,
100000000000000L,
1000000000000000L,
10000000000000000L,
100000000000000000L,
1000000000000000000L,
}

Constant long values for 10 ^(0...18) needed by conversion methods.

◆ readGroupChars

boolean readGroupChars

Denotes if grouping characters are ignored when parsing numbers if they are given (not set to '\0'). This applies to all number types.
Defaults to false. If set to true, grouping characters are just skipped when found while parsing numbers, no matter at which position they occur.

◆ signMask

final long signMask
static
Initial value:
= Double.doubleToRawLongBits(-0.0) ^
Double.doubleToRawLongBits(+0.0)

Used for float conversion

◆ thousandsGroupChar

char thousandsGroupChar

Defines the separator character for thousands when converting a number to a string representation. In addition, this is used to identify thousand group symbols when parsing decimal values. If set to '\0', no group separator is written and also when parsing, a group separator is not accepted. If set, still writeGroupChars controls if it is written.
Defaults to ','. By invoking setFromLocale(), the current locale's setting is determined.

◆ whitespaces

char [] whitespaces

Defines whitespace characters that are ignored when leading the number and after the sign-character. Applies to methods parseInt and parseFloat. In contrast, methods parseDec, parseBin, parseHex and parseOct do not ignore any whitespace characters.

◆ writeExponentPlusSign

boolean writeExponentPlusSign

Determines if positive exponent values are prepended with an explicit '+' character when written using writeFloat.
Defaults to false, as some systems will not accept a plus sign on the exponent value. Note that field plusSign is not applicable for exponent numbers.

◆ writeGroupChars

boolean writeGroupChars

Denotes if grouping characters are written if they are given (not set to '\0'). This applies to all number types.
Defaults to false.


The documentation for this class was generated from the following file: