Class NumberFormat
- All Implemented Interfaces:
INumberFormat
,Serializable
Syntax: {options}format;negative-spec;positive-spec
- options
The option set is optional and must be surrounded with {} when used. It represents a key value mechanism separated by ',' signs. Examples include: a=b,q=e meaning a is set to b and q is set to e. Valid options are:
- locale=nl-NL
This specifies a locale in the option set overriding the one of the NumberFormats' class.
- locale=nl-NL
- format
The format pattern which actually specified how the number should look like consists of a decimal part and an * fractional part. divided by a '.' when a fractional part is required.
- decimal
Decimal part specifies how grouping, minimum decimal and maximum decimal digits. For example a pattern: #,##0 specifies at least 1 decimal digit ( which is always the case ) and grouping every 3 decimal digits. With a maximumof 4 decimal digits. At least 1 zero at the end of the decimal syntax is required for the pattern to parse.
- fractional
The fractional part begins if there is a decimal separator '.'. If there is no decimal separator there is no fractional part. The fractional part specifies how many minimum fraction digits there are required and how many fraction digits at max are allowed. For example a syntax 0.00## will specify that at least two fractional should be displayed and at most four.
- decimal
- negative-spec
Negative pattern has only 2 special characters: '#' and ';'. The '#' will dictate the actual number pattern specified earlier. For example: 0.0;(#) will specifiy that a negative number is prefixed with '(' and postfixed with ')' While * ';' will end the pattern part and proceed to the positive specification
- positive-spec
The positive pattern has only 1 special character: '#'. The '#' will dictate the actual number pattern specified earlier. For example: 0.0;(#) will specifiy that a negative number is prefixed with '(' and postfixed with ')'
- "##0" output is like 23 for US locale's and will not use or accept any fractional digits string
- "##0.00" output is like 23.00 for US locale's
- "000.00" output is like 023.00 for US locale's
- "000.00;-#" -23 outputs like -023.00 for US locale's
- "000.00;-#;+#" 23 outputs like +023.00 for US locale's
- "{locale=NL-nl}000.00;-#;+#" 23 outputs like +023,00 for the specified NL locale.
- Since:
- 6.0
- Author:
- F. van der Meer
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionNumberFormat
(Locale locale, String pattern) Constructs a number format based on a locale and a pattern. -
Method Summary
Modifier and TypeMethodDescriptionformat
(double number) Formats an integer number to it's string representation.format
(long number) Formats an integer number to it's string representation.double
This method parses an input text and returns the corresponding number value.long
parseInteger
(String text) This method parses an input text and returns the corresponding number value.
-
Constructor Details
-
NumberFormat
Constructs a number format based on a locale and a pattern. The pattern is parsed according to the specifications ofNumberFormat
- Parameters:
locale
- The locale from which the system gains the decimal symbols.pattern
- The pattern specifying the decimal pattern as described in the class header.- Throws:
PatternException
- When the pattern was invalid.
-
-
Method Details
-
format
Description copied from interface:INumberFormat
Formats an integer number to it's string representation. The implementor of this interface should be able to parse string that is returned as well.- Specified by:
format
in interfaceINumberFormat
- Parameters:
number
- The number to format.- Returns:
- The string representation of this number which should never be null
-
format
Description copied from interface:INumberFormat
Formats an integer number to it's string representation. The implementor of this interface should be able to parse the string that was returned as well.- Specified by:
format
in interfaceINumberFormat
- Parameters:
number
- The number to format.- Returns:
- The string representation of this number which should never be null
-
parse
Description copied from interface:INumberFormat
This method parses an input text and returns the corresponding number value. The complete text should be a number during parse. If the parse fails an- Specified by:
parse
in interfaceINumberFormat
- Parameters:
text
- The text to parse, which should never be a null pointer.- Returns:
- The double value parsed from the text.
-
parseInteger
Description copied from interface:INumberFormat
This method parses an input text and returns the corresponding number value. The complete text should be a number during parse. If the parse fails an- Specified by:
parseInteger
in interfaceINumberFormat
- Parameters:
text
- The text to parse, which should never be a null pointer.- Returns:
- The double value parsed from the text.
-