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 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 com.ibm.icu.text.DecimalFormat`
`decimalFormat`
`protected char`
`decimalSeparator`
The default format of Double is Double.toString(); need to localize the result of Double.toString() to get the final result.
`protected String`
`formatPattern`
the format pattern
`protected com.ibm.icu.util.ULocale`
`locale`
the locale used for formatting
`protected static Logger`
`logger`
logger used to log syntax errors.
`protected com.ibm.icu.text.NumberFormat`
`numberFormat`
a java.text.NumberFormat format object.
`protected boolean`
`parseBigDecimal`
Flag whether to parse numbers and return BigDecimal values.

## Constructor Summary

Constructors
Constructor
Description
`NumberFormatter()`
constructor with no argument
`NumberFormatter(com.ibm.icu.util.ULocale locale)`
`NumberFormatter(String format)`
constructor with a format string as parameter
`NumberFormatter(String pattern, com.ibm.icu.util.ULocale locale)`
constructor that takes a format pattern and a locale
`NumberFormatter(String pattern, Locale locale)`
Deprecated.
since 2.1
`NumberFormatter(Locale locale)`
Deprecated.
since 2.1

## Method Summary

Modifier and Type
Method
Description
`void`
`applyPattern(String patternStr)`
initializes numeric format pattern
`String`
`format(double num)`
`String`
`format(long num)`
formats a long integer
`String`
`format(Number number)`
`String`
`format(BigDecimal bigDecimal)`
formats a BigDecimal value into a string
`String`
`formatValue(Object value)`
format the value object into a string.
`String`
`getFormatCode()`
`String`
`getPattern()`
returns the original format string.
`boolean`
`isParseBigDecimal()`
Returns whether decimal numbers are returned as BigDecimal instances.
`Number`
`parse(String number)`
Parses the input string into a formatted date type.
`void`
`setParseBigDecimal(boolean parseBigDecimal)`
Sets whether decimal numbers must be returned as BigDecimal instances.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### logger

protected static Logger logger
logger used to log syntax errors.

### formatPattern

protected 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 com.ibm.icu.text.NumberFormat numberFormat
a 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 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:
  - invalid reference

        of java.text.DecimalFormatSymbols#exponential

## Constructor Details

### NumberFormatter

public NumberFormatter()
constructor with no argument

### NumberFormatter

public NumberFormatter(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(Locale locale)
Deprecated.
since 2.1

### NumberFormatter

public NumberFormatter(String pattern, com.ibm.icu.util.ULocale locale)
constructor that takes a format pattern and a locale

Parameters:
  `pattern` - numeric format pattern
  `locale` - locale used to format the number

### NumberFormatter

@Deprecated public NumberFormatter(String pattern, Locale locale)
Deprecated.
since 2.1

## Method Details

### getPattern

public String getPattern()
returns the original format string.

### getFormatCode

public String getFormatCode()

### applyPattern

public void applyPattern(String patternStr)
initializes numeric format pattern

Parameters:
  `patternStr` - ths string used for formatting numeric data

### format

public String format(double num)

Parameters:
  `num` - the number to be formatted
Returns:
  the formatted string

### format

public String format(BigDecimal bigDecimal)
formats a BigDecimal value into a string

Parameters:
  `big` - decimal value
Returns:
  formatted string

### format

public String format(Number number)

### format

public 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 Number parse(String number) throws ParseException
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

public String formatValue(Object value)
Description copied from interface: `IFormatter`
format the value object into a string.

Specified by:
  `formatValue` in interface `IFormatter`
Parameters:
  `value` -
Returns: