Parse a number with NumberFormat and Locale.CANADA : NumberFormat « I18N « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » I18N » NumberFormat 
13.14.9.Parse a number with NumberFormat and Locale.CANADAPrevious/Next
import java.text.NumberFormat;
import java.util.Locale;

public class Main {
  public static void main(String[] argvthrows Exception {

    Number number = NumberFormat.getPercentInstance(Locale.CANADA).parse("123.45%");
    // 1.2345
    if (number instanceof Long) {
      System.out.println("Long value");
    else {
      System.out.println("Double value");
    }
  }
}
13.14.NumberFormat
13.14.1.Format for GERMAN locale
13.14.2.Format for the default locale
13.14.3.Parse a GERMAN number
13.14.4.Formatting a Number in Exponential Notation
13.14.5.Using only 0's to the left of E forces no decimal point
13.14.6.Formatting and Parsing Locale-Specific Currency
13.14.7.Parse number with NumberFormat and Locale
13.14.8.Formatting and Parsing a Locale-Specific Percentage
13.14.9.Parse a number with NumberFormat and Locale.CANADA
13.14.10.Format a number with DecimalFormat
13.14.11.Parse a number for a locale
13.14.12.Format a number for a locale
13.14.13.Use java.text.NumberFormat to format a currency value.
13.14.14.Use grouping to display a number
13.14.15.Set format to two decimal places
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.