Java Doc for NumberFormat.java in  » Ajax » GWT » com » google » gwt » i18n » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » GWT » com.google.gwt.i18n.client 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.google.gwt.i18n.client.NumberFormat

NumberFormat
public class NumberFormat (Code)
Formats and parses numbers using locale-sensitive patterns. This class provides comprehensive and flexible support for a wide variety of localized formats, including
  • Locale-specific symbols such as decimal point, group separator, digit representation, currency symbol, percent, and permill
  • Numeric variations including integers ("123"), fixed-point numbers ("123.4"), scientific notation ("1.23E4"), percentages ("12%"), and currency amounts ("$123")
  • Predefined standard patterns that can be used both for parsing and formatting, including NumberFormat.getDecimalFormat() decimal , NumberFormat.getCurrencyFormat() currency , NumberFormat.getPercentFormat() percentages , and NumberFormat.getScientificFormat() scientific
  • Custom patterns and supporting features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits

Patterns

Formatting and parsing are based on customizable patterns that can include a combination of literal characters and special characters that act as placeholders and are replaced by their localized counterparts. Many characters in a pattern are taken literally; they are matched during parsing and output unchanged during formatting. Special characters, on the other hand, stand for other characters, strings, or classes of characters. For example, the '#' character is replaced by a localized digit.

Often the replacement character is the same as the pattern character. In the U.S. locale, for example, the ',' grouping character is replaced by the same character ','. However, the replacement is still actually happening, and in a different locale, the grouping character may change to a different character, such as '.'. Some special characters affect the behavior of the formatter by their presence. For example, if the percent character is seen, then the value is multiplied by 100 before being displayed.

The characters listed below are used in patterns. Localized symbols use the corresponding characters taken from corresponding locale symbol collection, which can be found in the properties files residing in the com.google.gwt.i18n.client.constants. To insert a special character in a pattern as a literal (that is, without any special meaning) the character must be quoted. There are some exceptions to this which are noted below.

Symbol Location Localized? Meaning
0 Number Yes Digit
# Number Yes Digit, zero shows as absent
. Number Yes Decimal separator or monetary decimal separator
- Number Yes Minus sign
, Number Yes Grouping separator
E Number Yes Separates mantissa and exponent in scientific notation; need not be quoted in prefix or suffix
E Subpattern boundary Yes Separates positive and negative subpatterns
% Prefix or suffix Yes Multiply by 100 and show as percentage
\u2030 (\u005Cu2030) Prefix or suffix Yes Multiply by 1000 and show as per mille
\u00A4 (\u005Cu00A4) Prefix or suffix No Currency sign, replaced by currency symbol; if doubled, replaced by international currency symbol; if present in a pattern, the monetary decimal separator is used instead of the decimal separator
' Prefix or suffix No Used to quote special characters in a prefix or suffix; for example, "'#'#" formats 123 to "#123"; to create a single quote itself, use two in succession, such as "# o''clock"

A NumberFormat pattern contains a postive and negative subpattern separated by a semicolon, such as "#,##0.00;(#,##0.00)". Each subpattern has a prefix, a numeric part, and a suffix. If there is no explicit negative subpattern, the negative subpattern is the localized minus sign prefixed to the positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are ignored in the negative subpattern. That means that "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".

The prefixes, suffixes, and various symbols used for infinity, digits, thousands separators, decimal separators, etc. may be set to arbitrary values, and they will appear properly during formatting. However, care must be taken that the symbols and strings do not conflict, or parsing will be unreliable. For example, the decimal separator and thousands separator should be distinct characters, or parsing will be impossible.

The grouping separator is a character that separates clusters of integer digits to make large numbers more legible. It commonly used for thousands, but in some locales it separates ten-thousands. The grouping size is the number of digits between the grouping separators, such as 3 for "100,000,000" or 4 for "1 0000 0000".

Pattern Grammar (BNF)

The pattern itself uses the following grammar:

pattern := subpattern (';' subpattern)?
subpattern := prefix? number exponent? suffix?
number := (integer ('.' fraction)?) | sigDigits
prefix := '\u005Cu0000'..'\u005CuFFFD' - specialCharacters
suffix := '\u005Cu0000'..'\u005CuFFFD' - specialCharacters
integer := '#'* '0'*'0'
fraction := '0'* '#'*
sigDigits := '#'* '@''@'* '#'*
exponent := 'E' '+'? '0'* '0'
padSpec := '*' padChar
padChar := '\u005Cu0000'..'\u005CuFFFD' - quote

Notation:

X* 0 or more instances of X
X? 0 or 1 instances of X
X|Y either X or Y
C..D any character from C up to D, inclusive
S-T characters in S, except those in T

The first subpattern is for positive numbers. The second (optional) subpattern is for negative numbers.




Constructor Summary
protected  NumberFormat(NumberConstants numberConstants, CurrencyCodeMapConstants currencyCodeMapConstants, String pattern, String currencyCode)
     Constructs a format object based on the specified settings.
protected  NumberFormat(String pattern, String currencyCode)
     Constructs a format object for the default locale based on the specified settings.

Method Summary
public  Stringformat(double number)
     This method formats a double to produce a string.
public static  NumberFormatgetCurrencyFormat()
     Provides the standard currency format for the default locale.
public static  NumberFormatgetDecimalFormat()
     Provides the standard decimal format for the default locale.
public static  NumberFormatgetFormat(String pattern)
     Gets a NumberFormat instance for the default locale using the specified pattern and the default currencyCode.
public static  NumberFormatgetFormat(String pattern, String currencyCode)
     Gets a custom NumberFormat instance for the default locale using the specified pattern and currency code.
public  StringgetPattern()
     Returns the pattern used by this number format.
public static  NumberFormatgetPercentFormat()
     Provides the standard percent format for the default locale.
public static  NumberFormatgetScientificFormat()
     Provides the standard scientific format for the default locale.
public  doubleparse(String text)
     Parses text to produce a numeric value.
public  doubleparse(String text, int[] inOutPos)
     Parses text to produce a numeric value.

The method attempts to parse text starting at the index given by pos.



Constructor Detail
NumberFormat
protected NumberFormat(NumberConstants numberConstants, CurrencyCodeMapConstants currencyCodeMapConstants, String pattern, String currencyCode)(Code)
Constructs a format object based on the specified settings.
Parameters:
  numberConstants - the locale-specific number constants to use for thisformat
Parameters:
  currencyCodeMapConstants - the locale-specific currency code map touse for this format
Parameters:
  pattern - pattern that specify how number should be formatted
Parameters:
  currencyCode - currency that should be used



NumberFormat
protected NumberFormat(String pattern, String currencyCode)(Code)
Constructs a format object for the default locale based on the specified settings.
Parameters:
  pattern - pattern that specify how number should be formatted
Parameters:
  currencyCode - currency that should be used




Method Detail
format
public String format(double number)(Code)
This method formats a double to produce a string.
Parameters:
  number - The double to format the formatted number string



getCurrencyFormat
public static NumberFormat getCurrencyFormat()(Code)
Provides the standard currency format for the default locale. a NumberFormat capable of producing and consumingcurrency format for the default locale



getDecimalFormat
public static NumberFormat getDecimalFormat()(Code)
Provides the standard decimal format for the default locale. a NumberFormat capable of producing and consumingdecimal format for the default locale



getFormat
public static NumberFormat getFormat(String pattern)(Code)
Gets a NumberFormat instance for the default locale using the specified pattern and the default currencyCode.
Parameters:
  pattern - pattern for this formatter a NumberFormat instance
throws:
  IllegalArgumentException - if the specified pattern is invalid



getFormat
public static NumberFormat getFormat(String pattern, String currencyCode)(Code)
Gets a custom NumberFormat instance for the default locale using the specified pattern and currency code.
Parameters:
  pattern - pattern for this formatter
Parameters:
  currencyCode - international currency code a NumberFormat instance
throws:
  IllegalArgumentException - if the specified pattern is invalid



getPattern
public String getPattern()(Code)
Returns the pattern used by this number format.



getPercentFormat
public static NumberFormat getPercentFormat()(Code)
Provides the standard percent format for the default locale. a NumberFormat capable of producing and consumingpercent format for the default locale



getScientificFormat
public static NumberFormat getScientificFormat()(Code)
Provides the standard scientific format for the default locale. a NumberFormat capable of producing and consumingscientific format for the default locale



parse
public double parse(String text)(Code)
Parses text to produce a numeric value. A NumberFormatException is thrown if either the text is empty or if the parse does not consume all characters of the text.
Parameters:
  text - the string being parsed a parsed number value
throws:
  NumberFormatException - if the entire text could not be convertedinto a number



parse
public double parse(String text, int[] inOutPos)(Code)
Parses text to produce a numeric value.

The method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed number is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed.


Parameters:
  text - the string to be parsed
Parameters:
  inOutPos - position to pass in and get back a double value representing the parsed number, or 0.0if the parse fails



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.