• <tfoot id='lDwIo'></tfoot>
  • <legend id='lDwIo'><style id='lDwIo'><dir id='lDwIo'><q id='lDwIo'></q></dir></style></legend>
      • <bdo id='lDwIo'></bdo><ul id='lDwIo'></ul>

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

      1. <small id='lDwIo'></small><noframes id='lDwIo'>

        是否 &lt;f:convertNumber&gt;使用模式格式化货币时使用正确的数字分隔符?

        时间:2023-10-14
          <tfoot id='0QGua'></tfoot>

              <tbody id='0QGua'></tbody>
                • <bdo id='0QGua'></bdo><ul id='0QGua'></ul>

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

                  <small id='0QGua'></small><noframes id='0QGua'>

                  本文介绍了是否 &lt;f:convertNumber&gt;使用模式格式化货币时使用正确的数字分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有以下 <f:convertNumber> 来格式化货币类型数字:

                  Suppose I have the following <f:convertNumber> to format a currency-type number:

                  <f:convertNumber type="currency" locale="#{userSession.locale}" pattern="$###,###.###" />
                  

                  在英语中,一百万是 1,000,000,但在德国,应该是 1.000.000.我的问题是:如果我使用上述模式,JSF 会知道指定语言环境的数字格式并自动使用正确的分隔符吗?

                  In English, a million would be 1,000,000 but in Germany, it should be 1.000.000. My question is: If I use the above pattern, will JSF be aware of the number format of the specified locale and automatically use the correct separator?

                  如果不是,如果您能告诉我如何格式化货币数字并同时指定正确的数字分隔符,我将不胜感激.

                  If not, I'd be very grateful if you could show me how I can format a currency number and at the same time specify the right number separator.

                  推荐答案

                  了解和理解 <f:convertNumber> 标签使用 DecimalFormat 在幕后.您可以在 其 javadoc 中找到所有模式字符.

                  It's important to know and understand that the <f:convertNumber> tag uses DecimalFormat under the covers. You can find all pattern characters in its javadoc.

                  您似乎期望 DecimalFormat 模式字符 . 也实际用于最终格式.这是不真实的.它实际上只是模式字符(如使用的dMy等简单日期格式).基本上,模式字符 , 告诉 DecimalFormat 打印由给定语言环境指定的分组分隔符",等效地,模式字符 .告诉 DecimalFormat 打印由给定语言环境指定的小数分隔符".

                  It seems that you expected that the DecimalFormat pattern characters , and . are also actually used in the final format. This is untrue. It are really merely pattern characters (like as d, M, y, etc as used bySimpleDateFormat). Basically, the pattern character , tells DecimalFormat to print the "grouping separator" as specified by the given locale and, equivalently, the pattern character . tells DecimalFormat to print the "decimal separator" as specified by the given locale.

                  实际上,实际打印的字符取决于给定的语言环境.对于英语语言环境 (locale="en"),打印的分组分隔符"恰好也是 ,,但对于德语语言环境 (locale="de") 正在打印的分组分隔符"确实是 ..

                  In effects, the actual character being printed depends on the given locale. For English locale (locale="en"), the "grouping separator" being printed is just coincidentally also ,, but for German locale (locale="de") the "grouping separator" being printed is indeed ..

                  与具体问题无关,如果pattern,type属性完全没有作用 属性被指定.type 属性在此示例中基本上是多余的,可以安全地删除而不会产生任何副作用.

                  Unrelated to the concrete problem, the type attribute of <f:convertNumber> has totally no effect if the pattern attribute is specified. The type attribtue is basically superfluous in this example and can safely be removed without any side effects.

                  如果您删除 pattern 属性,那么它实际上会被使用,并且您会看到正在使用货币的默认模式,这与 ¤# 相同,##0.00 用于英语语言环境,¤ #,##0.00 用于德语语言环境.还要注意表示货币符号的模式字符不是$,而是¤.货币符号可以通过 currencySymbol 属性单独设置.因此,货币的正确方法是:

                  If you remove the pattern attribute, then it'll actually be used and you'll see that the default pattern for a currency is being used, which is same as ¤#,##0.00 for English locale and ¤ #,##0.00 for German locale. Also note that the pattern character representing the currency symbol is not $, but ¤. The currency symbol can be set separately via currencySymbol attribute. So the correct approach for currencies would be:

                  <f:convertNumber type="currency" locale="#{userSession.locale}" currencySymbol="$" />
                  

                  再次,请参阅之前链接的 DecimalFormat javadoc.

                  Again, see the DecimalFormat javadoc as linked before.

                  这篇关于是否 &lt;f:convertNumber&gt;使用模式格式化货币时使用正确的数字分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将两位数格式的整数保存在Java中的变量中 下一篇:Java Double 值 = 0.01 更改为 0.009999999999999787

                  相关文章

                • <tfoot id='xgZjj'></tfoot>
                  1. <small id='xgZjj'></small><noframes id='xgZjj'>

                    <legend id='xgZjj'><style id='xgZjj'><dir id='xgZjj'><q id='xgZjj'></q></dir></style></legend>

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