<i id='WJuxn'><tr id='WJuxn'><dt id='WJuxn'><q id='WJuxn'><span id='WJuxn'><b id='WJuxn'><form id='WJuxn'><ins id='WJuxn'></ins><ul id='WJuxn'></ul><sub id='WJuxn'></sub></form><legend id='WJuxn'></legend><bdo id='WJuxn'><pre id='WJuxn'><center id='WJuxn'></center></pre></bdo></b><th id='WJuxn'></th></span></q></dt></tr></i><div id='WJuxn'><tfoot id='WJuxn'></tfoot><dl id='WJuxn'><fieldset id='WJuxn'></fieldset></dl></div>
  • <tfoot id='WJuxn'></tfoot>

    <small id='WJuxn'></small><noframes id='WJuxn'>

  • <legend id='WJuxn'><style id='WJuxn'><dir id='WJuxn'><q id='WJuxn'></q></dir></style></legend>

          <bdo id='WJuxn'></bdo><ul id='WJuxn'></ul>
      1. 在 Java 中的外国语言环境中格式化货币

        Formatting Currencies in Foreign Locales in Java(在 Java 中的外国语言环境中格式化货币)

            <small id='HooiW'></small><noframes id='HooiW'>

              <i id='HooiW'><tr id='HooiW'><dt id='HooiW'><q id='HooiW'><span id='HooiW'><b id='HooiW'><form id='HooiW'><ins id='HooiW'></ins><ul id='HooiW'></ul><sub id='HooiW'></sub></form><legend id='HooiW'></legend><bdo id='HooiW'><pre id='HooiW'><center id='HooiW'></center></pre></bdo></b><th id='HooiW'></th></span></q></dt></tr></i><div id='HooiW'><tfoot id='HooiW'></tfoot><dl id='HooiW'><fieldset id='HooiW'></fieldset></dl></div>
              1. <legend id='HooiW'><style id='HooiW'><dir id='HooiW'><q id='HooiW'></q></dir></style></legend>

                • <bdo id='HooiW'></bdo><ul id='HooiW'></ul>

                    <tbody id='HooiW'></tbody>
                  <tfoot id='HooiW'></tfoot>

                • 本文介绍了在 Java 中的外国语言环境中格式化货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尽我最大的努力寻找一种方法,使用 Java 来在各种语言环境中格式化外币,这些语言不是该货币的默认设置.我找到了 java.util.Currency,它可以代表用于各种语言环境的正确符号.也就是说,对于美元,它在美国为我提供符号 $,在其他国家提供美元或美元.此外,我还找到了 java.text.NumberFormat,它将为特定语言环境格式化货币.我的问题 - util.Currency 将提供适当的符号和代码来表示其非默认语言环境中的货币,但不会以任何特定于语言环境的方式格式化货币.NumberFormat 假定我传递给它的数字(带有语言环境)是该语言环境的货币,而不是外币.

                  I'm doing my best to find a way to format foreign currencies across various locales which are not default for that currency, using Java. I've found java.util.Currency, which can represent the proper symbol to use for various locales. That is, for USD, it provides me the symbol $ in the US, and US$ or USD in other nations. Also, I've found java.text.NumberFormat, which will format a currency for a specific locale. My problem - util.Currency will provide proper symbols and codes for representing currencies in their non-default locales, but will not format currency in any locale-specific way. NumberFormat assumes that the number I pass it, with a locale, is the currency of that locale, not a foreign currency.

                  例如,如果我使用 getCurrencyInstance(Locale.GERMANY) 然后格式化 (1000) 它假定我正在格式化 1000 欧元.实际上,对于美元、日元或任何其他货币,我可能需要正确的德语本地化表示(正确的小数和千位分隔符,无论是在金额之前还是之后放置符号).到目前为止,我能够得出的最好的结果是使用 NumberFormat 格式化数字,然后在输出中搜索非数字字符并将它们替换为从 util.Currency 派生的符号.但是,这非常脆弱,对于我的目的来说可能不够可靠.想法?任何帮助深表感谢.

                  For example, if I use getCurrencyInstance(Locale.GERMANY) and then format (1000) it assumes I am formatting 1000 euro. In reality, I may need the correct German-localized representation (correct decimal and thousands separator, whether to put the symbol before or after the amount) for USD, or Yen, or any other currency. The best I've been able to derive so far is to format a number using NumberFormat, then search the output for non-digit characters and replace them with symbols derived from util.Currency. However, this is very brittle, and probably not reliable enough for my purposes. Ideas? Any help is much appreciated.

                  推荐答案

                  尝试使用setCurrency 在 getCurrencyInstance(Locale.GERMANY) 返回的实例上

                  Try using setCurrency on the instance returned by getCurrencyInstance(Locale.GERMANY)

                  坏了:

                  java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY);
                  System.out.println(format.format(23));
                  

                  产出:23,00 欧元

                  Output: 23,00

                  固定:

                  java.util.Currency usd = java.util.Currency.getInstance("USD");
                  java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY);
                  format.setCurrency(usd);
                  System.out.println(format.format(23));
                  

                  产出:23,00 美元

                  Output: 23,00 USD

                  这篇关于在 Java 中的外国语言环境中格式化货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)
                • <tfoot id='sjo7k'></tfoot>

                  <small id='sjo7k'></small><noframes id='sjo7k'>

                  <legend id='sjo7k'><style id='sjo7k'><dir id='sjo7k'><q id='sjo7k'></q></dir></style></legend>
                    <bdo id='sjo7k'></bdo><ul id='sjo7k'></ul>

                            <tbody id='sjo7k'></tbody>

                          1. <i id='sjo7k'><tr id='sjo7k'><dt id='sjo7k'><q id='sjo7k'><span id='sjo7k'><b id='sjo7k'><form id='sjo7k'><ins id='sjo7k'></ins><ul id='sjo7k'></ul><sub id='sjo7k'></sub></form><legend id='sjo7k'></legend><bdo id='sjo7k'><pre id='sjo7k'><center id='sjo7k'></center></pre></bdo></b><th id='sjo7k'></th></span></q></dt></tr></i><div id='sjo7k'><tfoot id='sjo7k'></tfoot><dl id='sjo7k'><fieldset id='sjo7k'></fieldset></dl></div>