Package org.eclipse.birt.core.format
Class NumberFormatter
- java.lang.Object
-
- org.eclipse.birt.core.format.NumberFormatter
-
- All Implemented Interfaces:
IFormatter
public class NumberFormatter extends java.lang.Object implements 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
Fields Modifier and Type Field Description protected java.text.DecimalFormatdecimalFormatprotected chardecimalSeparatorThe default format of Double is Double.toString(); need to localize the result of Double.toString() to get the final result.protected java.lang.StringformatPatternthe format patternprotected com.ibm.icu.util.ULocalelocalethe locale used for formattingprotected static java.util.logging.Loggerloggerlogger used to log syntax errors.protected java.text.NumberFormatnumberFormata java.text.NumberFormat format object.protected booleanparseBigDecimalFlag whether to parse numbers and return BigDecimal values.
-
Constructor Summary
Constructors Constructor Description NumberFormatter()constructor with no argumentNumberFormatter(com.ibm.icu.util.ULocale locale)NumberFormatter(java.lang.String format)constructor with a format string as parameterNumberFormatter(java.lang.String pattern, com.ibm.icu.util.ULocale locale)constructor that takes a format pattern and a localeNumberFormatter(java.lang.String pattern, java.util.Locale locale)Deprecated.since 2.1NumberFormatter(java.util.Locale locale)Deprecated.since 2.1
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyPattern(java.lang.String patternStr)initializes numeric format patternjava.lang.Stringformat(double num)java.lang.Stringformat(long num)formats a long integerjava.lang.Stringformat(java.lang.Number number)java.lang.Stringformat(java.math.BigDecimal bigDecimal)formats a BigDecimal value into a stringjava.lang.StringformatValue(java.lang.Object value)format the value object into a string.java.lang.StringgetFormatCode()java.lang.StringgetPattern()returns the original format string.booleanisParseBigDecimal()Returns whether decimal numbers are returned as BigDecimal instances.java.lang.Numberparse(java.lang.String number)Parses the input string into a formatted date type.voidsetParseBigDecimal(boolean parseBigDecimal)Sets whether decimal numbers must be returned as BigDecimal instances.
-
-
-
Field Detail
-
logger
protected static java.util.logging.Logger logger
logger used to log syntax errors.
-
formatPattern
protected java.lang.String formatPattern
the format pattern
-
parseBigDecimal
protected boolean parseBigDecimal
Flag whether to parse numbers and return BigDecimal values.
-
locale
protected com.ibm.icu.util.ULocale locale
the locale used for formatting
-
numberFormat
protected java.text.NumberFormat numberFormat
a java.text.NumberFormat format object. We want to use the createNumberFormat() and format() methods
-
decimalFormat
protected java.text.DecimalFormat decimalFormat
-
decimalSeparator
protected char decimalSeparator
The 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 Detail
-
NumberFormatter
public NumberFormatter()
constructor with no argument
-
NumberFormatter
public NumberFormatter(java.lang.String format)
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 public NumberFormatter(java.util.Locale locale)
Deprecated.since 2.1
-
NumberFormatter
public NumberFormatter(java.lang.String pattern, com.ibm.icu.util.ULocale locale)constructor that takes a format pattern and a locale- Parameters:
pattern- numeric format patternlocale- locale used to format the number
-
NumberFormatter
@Deprecated public NumberFormatter(java.lang.String pattern, java.util.Locale locale)Deprecated.since 2.1
-
-
Method Detail
-
getPattern
public java.lang.String getPattern()
returns the original format string.
-
getFormatCode
public java.lang.String getFormatCode()
-
applyPattern
public void applyPattern(java.lang.String patternStr)
initializes numeric format pattern- Parameters:
patternStr- ths string used for formatting numeric data
-
format
public java.lang.String format(double num)
- Parameters:
num- the number to be formatted- Returns:
- the formatted string
-
format
public java.lang.String format(java.math.BigDecimal bigDecimal)
formats a BigDecimal value into a string- Parameters:
big- decimal value- Returns:
- formatted string
-
format
public java.lang.String format(java.lang.Number number)
-
format
public java.lang.String format(long num)
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
public java.lang.Number parse(java.lang.String number) throws java.text.ParseExceptionParses the input string into a formatted date type.- Parameters:
number- the input string to parse- Returns:
- the formatted date
- Throws:
java.text.ParseException- if the beginning of the specified string cannot be parsed.
-
formatValue
public java.lang.String formatValue(java.lang.Object value)
Description copied from interface:IFormatterformat the value object into a string.- Specified by:
formatValuein interfaceIFormatter- Returns:
-
-