使用ICU包更改Java中的CHF货币模式? [英] Changing the pattern for CHF currency in Java using icu package?

查看:124
本文介绍了使用ICU包更改Java中的CHF货币模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Java函数来显示每种货币的语言环境模式.请参阅下面的功能.我有兴趣知道的是,为什么当货币为瑞士法郎时,第二位小数会硬编码为5? 请注意,我使用的是icu软件包,而java.util.Currency软件包不存在此问题.我使用的是en_US的默认语言环境. 以下是与美元和瑞士法郎货币相关的函数输出:

I wrote a java function that shows the locale pattern for each currency. See the function below. What I am interested to know is that why when the currency is CHF, the 2nd decimal is hardcoded to 5? Note that I am using icu package and this issue doesn't exist with java.util.Currency package. I am using the default locale of en_US. Here is the output of the function which is related to USD and CHF currencies:

Analyzing currency: [USD] localePattern: [¤#,##0.00;(¤#,##0.00)] Currency symbol [$]
Analyzing currency: [CHF] localePattern: [¤#,##0.05;(¤#,##0.05)] Currency symbol [SwF]

这是我写的Java函数:

Here is the java function I wrote:

import com.ibm.icu.text.DecimalFormat; 
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.util.Currency;

public static void main(String[] args)
  {
    Currency configuredCurrency                       = null; 
    NumberFormat formatter                = NumberFormat.getCurrencyInstance();
    DecimalFormat localeCurrencyFormatter = (DecimalFormat)formatter;
    String localePattern                  = "";
    String symbol                         = "";

    String currencies        = "AED,AFN,ALL,AMD,ARS,AUD,BGN,BHD,BND,BOB,BRL,BWP,BYR,CAD,CHF,CLP,CNY,COP,CRC,CZK,DJF,DKK,DOP,DZD,EEK,EGP,ERN,ETB,EUR,GBP,GTQ,HKD,HNL,HRK,HUF,IDR,ILS,INR,IQD,IRR,ISK,JOD,JPY,KES,KPW,KRW,KWD,KZT,LBP,LTL,LVL,LYD,MAD,MKD,MTL,MXN,MYR,NIO,NOK,NZD,OMR,PAB,PEN,PHP,PKR,PLN,PYG,QAR,RON,RUB,SAR,SDD,SEK,SGD,SKK,SOS,SVC,SYP,SwF,THB,TND,TRY,TZS,UAH,USD,UYU,VEB,VND,YER,ZAR,ZWD";
    String[] currenciesArray = currencies.split(",");

    for (int i = 0; i < currenciesArray.length; i++)
    {
      String currency = currenciesArray[i];
      configuredCurrency = Currency.getInstance(currency);
      localeCurrencyFormatter.setCurrency(configuredCurrency);
      localePattern = localeCurrencyFormatter.toPattern();
      symbol = localeCurrencyFormatter.getCurrency().getSymbol();

      System.out.println("Analyzing currency: [" + currency + "] localePattern: [" + localePattern + "] Currency symbol [" + symbol + "]");
    } 
  }

推荐答案

5是四舍五入的增量(没有0.01瑞士法郎,0.05是最不珍贵的硬币(

The 5 there is the rounding increment (there is no 0.01 of Swiss franc, 0.05 is the least valuable coin (Swiss franc wikipedia)).

也来自icu4j DecimalFormat

Also from the icu4j DecimalFormat javadoc:

代替'0',可以使用数字'1'至'9'表示舍入增量."

这篇关于使用ICU包更改Java中的CHF货币模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆