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

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

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

        <bdo id='0jRuP'></bdo><ul id='0jRuP'></ul>
    2. <tfoot id='0jRuP'></tfoot>
    3. 使用 Struts2 标签格式化数字

      时间:2023-09-30

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

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

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

            <legend id='Ms48p'><style id='Ms48p'><dir id='Ms48p'><q id='Ms48p'></q></dir></style></legend>
              • 本文介绍了使用 Struts2 标签格式化数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我想在我们的 jsp 页面中格式化一些数字.
                首先,我在我的属性中定义了一些资源
                format.number.with2Decimal={0,number,#0.00}

                ......
                问题1:
                我想知道‘#’和‘0’是什么意思?
                0.00,#0.00,##.00,###0.00
                谁能告诉我它们之间的区别?谢谢!

                问题2:
                如果我在操作中定义 BigDecimal 类型BigDecimal number1;

                那么我的页面应该使用一种格式来显示这个值,
                1.if number1=null then show -NIL-
                2.if number1=0 then show -NIL-
                3.if number1>0 then show 1.00,3434.98 .....
                请忽略数字<0

                问题3:
                将 number1 更改为字符串,
                1.如果 number1=null 或为空或空白则显示 -NIL-
                2.if number1=Hello then show Hello ....

                你能帮我吗?

                解决方案

                问题1:我想知道'#'和'0'是什么意思?0.00,#0.00,##.00,###0.00 谁能告诉我它们之间的区别?谢谢!

                • 0表示必须打印一个数字,不管它是否存在
                • # 表示一个数字如果存在则必须打印,否则省略.

                例子:

                 System.out.println("假设美国语言环境:" +"',' 作为千位分隔符," +'.'作为小数分隔符");NumberFormat nf = new DecimalFormat("#,##0.0##");System.out.println("
                ===============================");System.out.println("带格式(#,##0.0##)");System.out.println("------------------");System.out.println("1234.0 = " + nf.format(1234.0));System.out.println("123.4 = " + nf.format(123.4));System.out.println("12.34 = " + nf.format(12.34));System.out.println("1.234 = " + nf.format(1.234));System.out.println("==============================");nf = new DecimalFormat("#,000.000");System.out.println("
                ===============================");System.out.println("带格式(#,000.000)");System.out.println("------------------");System.out.println("1234.0 = " + nf.format(1234.0));System.out.println("123.4 = " + nf.format(123.4));System.out.println("12.34 = " + nf.format(12.34));System.out.println("1.234 = " + nf.format(1.234));System.out.println("==============================");

                运行示例

                输出:

                <块引用>

                假设美国语言环境:',' 作为千位分隔符,'.'作为小数分隔符)===============================带格式 (#,##0.0##)------------------------------1234.0 = 1,234.0123.4 = 123.412.34 = 12.341.234 = 1.234==============================================================带格式 (#,000.000)------------------------------1234.0 = 1,234.000123.4 = 123.40012.34 = 012.3401.234 = 001.234===============================

                在 Struts2 中,您可以使用 ActionSupport 中的 getText() 函数应用这种格式.

                P.S:问题 2 和 3 很琐碎(而且很混乱).

                I want to format some numbers in our jsp pages.
                first i define some resources in my porperties
                format.number.with2Decimal={0,number,#0.00}

                ......
                Question1:
                i want to know what is the ‘#’ and '0' means?
                0.00,#0.00,##.00,###0.00
                who can tell me the differences between them? thanks!

                Question2:
                if i define a BigDecimal type in my action BigDecimal number1;

                Then my page should using a format to show this value,
                1.if number1=null then show -NIL-
                2.if number1=0 then show -NIL-
                3.if number1>0 then show 1.00,3434.98 .....
                please ignore number<0

                Question3:
                change number1 to a String,
                1.if number1=null or empty or blank then show -NIL-
                2.if number1=Hello then show Hello ....

                could you give me help?

                解决方案

                Question1: i want to know what is the ‘#’ and '0' means? 0.00,#0.00,##.00,###0.00 who can tell me the differences between them? thanks!

                • 0 means that a number must be printed, no matter if it exists
                • # means that a number must be printed if it exists, omitted otherwise.

                Example:

                    System.out.println("Assuming US Locale: " + 
                                             "',' as thousand separator, " + 
                                             "'.' as decimal separator   ");
                
                    NumberFormat nf = new DecimalFormat("#,##0.0##");
                    System.out.println("
                ==============================");
                    System.out.println("With Format (#,##0.0##) ");
                    System.out.println("------------------------------");
                    System.out.println("1234.0 = " + nf.format(1234.0));
                    System.out.println("123.4  = " + nf.format(123.4));
                    System.out.println("12.34  = " + nf.format(12.34));
                    System.out.println("1.234  = " + nf.format(1.234));
                    System.out.println("==============================");
                
                    nf = new DecimalFormat("#,000.000");
                    System.out.println("
                ==============================");
                    System.out.println("With Format (#,000.000) ");
                    System.out.println("------------------------------");
                    System.out.println("1234.0 = " + nf.format(1234.0));
                    System.out.println("123.4  = " + nf.format(123.4));
                    System.out.println("12.34  = " + nf.format(12.34));
                    System.out.println("1.234  = " + nf.format(1.234));
                    System.out.println("==============================");
                

                Running Example

                Output:

                Assuming US Locale: ',' as thousand separator, '.' as decimal separator)
                
                ==============================
                With Format (#,##0.0##) 
                ------------------------------
                1234.0 = 1,234.0
                123.4  = 123.4
                12.34  = 12.34
                1.234  = 1.234
                ==============================
                
                ==============================
                With Format (#,000.000) 
                ------------------------------
                1234.0 = 1,234.000
                123.4  = 123.400
                12.34  = 012.340
                1.234  = 001.234
                ==============================
                

                In Struts2, you can apply this kind of format with the getText() function from ActionSupport.

                P.S: Question 2 and 3 are trivial (and messy).

                这篇关于使用 Struts2 标签格式化数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:语言环境的 Java 日期格式 下一篇:Java 使用特定格式的级别顺序打印二叉树

                相关文章

                最新文章

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

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

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