🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.programmer
Article #632

i18n and numbers

#632
From: Frederik Hansen
Date: Wed, 24 May 2000 00:00
77 lines
2914 bytes
Hi,

The following test program does not convert numbers into correct chinse
numbers, 
but still shows the 1,2,3,4 etc number. Should it not have been the
chinse 
charaters for the numbers? Or this there another way around?

import java.util.*;
import java.text.*;

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"),
          new Locale("zh","CN"),
          Locale.getDefault()
      };

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

}


Regards, 

Frederik
Technical Details
Message-ID: <392B9315.B5D7CF66@roirex.dk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f9a23,73ef4cadaafd5728,start
X-Google-Attributes: gidf9a23,public
X-Google-Thread: 10a146,73ef4cadaafd5728,start
X-Google-Attributes: gid10a146,public
From: Frederik Hansen <frederik@roirex.dk>
Subject: i18n and numbers
Date: 2000/05/24
Message-ID: <392B9315.B5D7CF66@roirex.dk>
X-Deja-AN: 626625814
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: Department of Written Abuse <abuse@news.inet.tele.dk>
X-Trace: news.inet.tele.dk 959157019 12056 194.182.128.2
Organization: Tele Danmark Internet Cyberspace Launchpad
Mime-Version: 1.0
Newsgroups: comp.lang.java.programmer,dk.edb.programmering.java