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

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

      <bdo id='tIMok'></bdo><ul id='tIMok'></ul>
  • <tfoot id='tIMok'></tfoot>

      1. <legend id='tIMok'><style id='tIMok'><dir id='tIMok'><q id='tIMok'></q></dir></style></legend>

        如何将字符串数字格式化为逗号和四舍五入?

        How can I format a String number to have commas and round?(如何将字符串数字格式化为逗号和四舍五入?)

        <small id='7XIIU'></small><noframes id='7XIIU'>

        <legend id='7XIIU'><style id='7XIIU'><dir id='7XIIU'><q id='7XIIU'></q></dir></style></legend>

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

                  <tbody id='7XIIU'></tbody>
                  本文介绍了如何将字符串数字格式化为逗号和四舍五入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  将以下数字格式化为字符串的最佳方法是什么?

                  What is the best way to format the following number that is given to me as a String?

                  String number = "1000500000.574" //assume my value will always be a String
                  

                  我希望这是一个字符串,其值为:1,000,500,000.57

                  I want this to be a String with the value: 1,000,500,000.57

                  我怎样才能这样格式化它?

                  How can I format it as such?

                  推荐答案

                  你可能想看看 DecimalFormat 类;它支持不同的语言环境(例如:在某些国家/地区会被格式化为 1.000.500.000,57).

                  您还需要将该字符串转换为数字,这可以通过以下方式完成:

                  You also need to convert that string into a number, this can be done with:

                  double amount = Double.parseDouble(number);
                  

                  代码示例:

                  String number = "1000500000.574";
                  double amount = Double.parseDouble(number);
                  DecimalFormat formatter = new DecimalFormat("#,###.00");
                  
                  System.out.println(formatter.format(amount));
                  

                  这篇关于如何将字符串数字格式化为逗号和四舍五入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <legend id='Rc1iB'><style id='Rc1iB'><dir id='Rc1iB'><q id='Rc1iB'></q></dir></style></legend>

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

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

                          <bdo id='Rc1iB'></bdo><ul id='Rc1iB'></ul>
                            <tfoot id='Rc1iB'></tfoot>