Package org.eclipse.birt.core.format
Class NumberFormatter
java.lang.Object
org.eclipse.birt.core.format.NumberFormatter
- All Implemented Interfaces:
IFormatter
Defines a number formatting class. It does the following: 1. In constructor,
convert format string to Java format string. 2. Expose a format function,
which does the following: a. Format number using Java format string b. Do
some post-processing, i.e., e or E, minus sign handling, etc.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.birt.core.format.IFormatter
IFormatter.DefaultFormatter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.ibm.icu.text.DecimalFormat
protected char
The default format of Double is Double.toString(); need to localize the result of Double.toString() to get the final result.protected String
the format patternprotected com.ibm.icu.util.ULocale
the locale used for formattingprotected static Logger
logger used to log syntax errors.protected com.ibm.icu.text.NumberFormat
a java.text.NumberFormat format object.protected boolean
Flag whether to parse numbers and return BigDecimal values. -
Constructor Summary
ConstructorsConstructorDescriptionconstructor with no argumentNumberFormatter
(com.ibm.icu.util.ULocale locale) NumberFormatter
(String format) constructor with a format string as parameterNumberFormatter
(String pattern, com.ibm.icu.util.ULocale locale) constructor that takes a format pattern and a localeNumberFormatter
(String pattern, Locale locale) Deprecated.since 2.1NumberFormatter
(Locale locale) Deprecated.since 2.1 -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyPattern
(String patternStr) initializes numeric format patternformat
(double num) format
(long num) formats a long integerformat
(BigDecimal bigDecimal) formats a BigDecimal value into a stringformatValue
(Object value) format the value object into a string.returns the original format string.boolean
Returns whether decimal numbers are returned as BigDecimal instances.Parses the input string into a formatted date type.void
setParseBigDecimal
(boolean parseBigDecimal) Sets whether decimal numbers must be returned as BigDecimal instances.
-
Field Details
-
logger
logger used to log syntax errors. -
formatPattern
the format pattern -
parseBigDecimal
protected boolean parseBigDecimalFlag whether to parse numbers and return BigDecimal values. -
locale
protected com.ibm.icu.util.ULocale localethe locale used for formatting -
numberFormat
protected com.ibm.icu.text.NumberFormat numberFormata java.text.NumberFormat format object. We want to use the createNumberFormat() and format() methods -
decimalFormat
protected com.ibm.icu.text.DecimalFormat decimalFormat -
decimalSeparator
protected char decimalSeparatorThe default format of Double is Double.toString(); need to localize the result of Double.toString() to get the final result. decimalSeparator is the localized decimal separator. currently the exponential character isnt exposed by JDK, so just leave it for future- See Also:
-
of java.text.DecimalFormatSymbols#exponential
-
-
Constructor Details
-
NumberFormatter
public NumberFormatter()constructor with no argument -
NumberFormatter
constructor with a format string as parameter- Parameters:
format
- format string
-
NumberFormatter
public NumberFormatter(com.ibm.icu.util.ULocale locale) - Parameters:
locale
- the locale used for numer format
-
NumberFormatter
Deprecated.since 2.1 -
NumberFormatter
constructor that takes a format pattern and a locale- Parameters:
pattern
- numeric format patternlocale
- locale used to format the number
-
NumberFormatter
Deprecated.since 2.1
-
-
Method Details
-
getPattern
returns the original format string. -
getFormatCode
-
applyPattern
initializes numeric format pattern- Parameters:
patternStr
- ths string used for formatting numeric data
-
format
- Parameters:
num
- the number to be formatted- Returns:
- the formatted string
-
format
formats a BigDecimal value into a string- Parameters:
big
- decimal value- Returns:
- formatted string
-
format
-
format
formats a long integer- Parameters:
num
- the number to be formatted- Returns:
- the formatted string
-
isParseBigDecimal
public boolean isParseBigDecimal()Returns whether decimal numbers are returned as BigDecimal instances.- Returns:
- the parseBigDecimal
-
setParseBigDecimal
public void setParseBigDecimal(boolean parseBigDecimal) Sets whether decimal numbers must be returned as BigDecimal instances.- Parameters:
parseBigDecimal
- the parseBigDecimal to set
-
parse
Parses the input string into a formatted date type.- Parameters:
number
- the input string to parse- Returns:
- the formatted date
- Throws:
ParseException
- if the beginning of the specified string cannot be parsed.
-
formatValue
Description copied from interface:IFormatter
format the value object into a string.- Specified by:
formatValue
in interfaceIFormatter
- Returns:
-