Java I18N: Format : Number Format : I18N « Development Class « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Development Class » I18NScreenshots 
Java I18N: Format : Number Format
Java I18N: Format : Number Format

/* From http://java.sun.com/docs/books/tutorial/index.html */

/*
 * Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.
 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for NON-COMMERCIAL purposes and without fee is hereby granted
 * provided that this copyright notice appears in all copies. Please refer to
 * the file "copyright.html" for further important copyright and licensing
 * information.
 
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
 * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */

import java.text.NumberFormat;
import java.util.Locale;

public class NumberFormatDemo {

  static public void displayNumber(Locale currentLocale) {

    Integer quantity = new Integer(123456);
    Double amount = new Double(345987.246);
    NumberFormat numberFormatter;
    String quantityOut;
    String amountOut;

    numberFormatter = NumberFormat.getNumberInstance(currentLocale);
    quantityOut = numberFormatter.format(quantity);
    amountOut = numberFormatter.format(amount);
    System.out.println(quantityOut + "   " + currentLocale.toString());
    System.out.println(amountOut + "   " + currentLocale.toString());
  }

  static public void displayCurrency(Locale currentLocale) {

    Double currency = new Double(9876543.21);
    NumberFormat currencyFormatter;
    String currencyOut;

    currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
    currencyOut = currencyFormatter.format(currency);
    System.out.println(currencyOut + "   " + currentLocale.toString());
  }

  static public void displayPercent(Locale currentLocale) {

    Double percent = new Double(0.75);
    NumberFormat percentFormatter;
    String percentOut;

    percentFormatter = NumberFormat.getPercentInstance(currentLocale);
    percentOut = percentFormatter.format(percent);
    System.out.println(percentOut + "   " + currentLocale.toString());
  }

  static public void main(String[] args) {

    Locale[] locales = new Locale("fr""FR")new Locale("de""DE"),
        new Locale("en""US") };

    for (int i = 0; i < locales.length; i++) {
      System.out.println();
      displayNumber(locales[i]);
      displayCurrency(locales[i]);
      displayPercent(locales[i]);
    }
  }

}


           
       
Related examples in the same category
1. I18N SortI18N Sort
2. Java I18N: Format : Choice Format DemoJava I18N: Format : Choice Format Demo
3. Java I18N: Format : Date FormatJava I18N: Format : Date Format
4. Java I18N: Format : Date Format Symbols DemoJava I18N: Format : Date Format Symbols Demo
5. Java I18N: Format : Message Format DemoJava I18N: Format : Message Format Demo
6. Java I18N: Format : Simple Date FormatJava I18N: Format : Simple Date Format
7. Java I18N: IntroductionJava I18N: Introduction
8. List all LocaleList all Locale
9. Displays Charsets and aliasesDisplays Charsets and aliases
10. Encode and DecodeEncode and Decode
11. List Locale OrientationList Locale Orientation
12. Resource Bundle in Java code
13. List Resource Bundle Creator
14. Simple Resource Bundle
15. Your own Resource Bundle
16. Displaying Formatted Numbers for Alternate LocalesDisplaying Formatted Numbers for Alternate Locales
17. Convert Encoding
18. Menu created from property file
19. Unicode DisplayUnicode Display
20. Demonstrate number and date internationalizationDemonstrate number and date internationalization
21. Set of convenience routines for internationalized code
22. Print the default locale
23. Use some locales choicesUse some locales choices
24. Format some values using the default locale
25. List LocalesList Locales
26. Create one button, internationalizedly
27. Show DateShow Date
28. Change the default locale
29. java.util.Locale and java.text.NumberFormatjava.util.Locale and java.text.NumberFormat
30. Collation Test Collation Test
31. Number Format Test Number Format Test
32. Java Internationalization: load string from properties Java Internationalization: load string from properties
33.  Locales  Locales
34. Locale 2Locale 2
35. Display Language OutputDisplay Language Output
36. Display Name OutputDisplay Name Output
37. Display Variant OutputDisplay Variant Output
38. Constant Locale UsageConstant Locale Usage
39. Country Language CodesCountry Language Codes
40. Isolating Locale-Specific Data with Resource Bundles Isolating Locale-Specific Data with Resource Bundles
41. Property To List Resource Bundle
42. Which Bundle Comes First
43. Calendar Manipulation for I18N (Internationalization)Calendar Manipulation for I18N (Internationalization)
44. Formatting Messages: Arabic DigitFormatting Messages: Arabic Digit
45. Formatting Messages: Change EraFormatting Messages: Change Era
46. Formatting Messages: Message Format ReuseFormatting Messages: Message Format Reuse
47. Character Sets and Unicode: Code Set Conversion
48. Searching, Sorting, and Text Boundary Detection: Collation IssuesSearching, Sorting, and Text Boundary Detection: Collation Issues
49. Searching, Sorting, and Text Boundary Detection: Detecting Text BoundariesSearching, Sorting, and Text Boundary Detection: Detecting Text Boundaries
50. Spanish SortSpanish Sort
51. Sort With Collation KeysSort With Collation Keys
52. DecompositionDecomposition
53. Formatting Messages: Date and NumberFormatting Messages: Date and Number
54. Internationalized Graphical User Interfaces: Component OrientationInternationalized Graphical User Interfaces: Component Orientation
55. Internationalized Graphical User Interfaces: Component Orientation 1Internationalized Graphical User Interfaces: Component Orientation 1
56. Localized JOptionPane
57. Big Demo for I18N
58. Component Orientation Bundle
59. Java Input Method Framework
60. Popup in FrenchPopup in French
61. I18N : TextI18N : Text
w_ww___.__ja___v_a__2_s._co__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.