我用的是displaytag1.2,现在列表显示中数字格式有2个问题
   1、0.72显示成.72,前面的0失踪。
   2、大于7位的数字会用科学计数法显示,如:12345678,显示为:1.2345678E7。我现在的需求是要求不用科学计数法。用displaytag的format属性好像没有用。还望论坛的高手指点迷津...谢谢!

解决方案 »

  1.   

    1、0.72显示成.72,前面的0失踪。
    format="{0,number,0.00}"2、大于7位的数字会用科学计数法显示,如:12345678,显示为:1.2345678E7。我现在的需求是要求不用科学计数法。 
    format="{0,number,#######0.00}"
      

  2.   


    You can use any valid java.text.MessageFormat pattern in the format attribute. Sorting will be based on the original object, not on the formatted String.
    Note that errors due to an invalid pattern/object combination (for example trying to format a String like a number) will not be rethrown. Instead, an error log will be written and the original unformatted object displayed.You can also use a format pattern along with column decorators (the pattern will be applied after the decoration).这是官方文档的说明。我现在是将数据取出来通过一个全部是String类型的VO对象封装,到页面上format就无作用。有什么好办法解决?
      

  3.   

    最好在取出的时候,就可以用NumberFormat格式转换你需要的格式,最后直接就可以显示了。
      

  4.   

    可以这样:NumberFormat fmt = new DecimalFormat("0.00");
    String str = fmt.format(0.72);
    System.out.println(str);fmt = new DecimalFormat("0");
    str = fmt.format(12345678);
    System.out.println(str);
      

  5.   

    我取值是通过如下:
    /**
     * @memo 作为ResultSet转向ArrayList公用类,
     */public class ResultRow {
    // --------------------------------------------------------- 
    //该bean作RS对象行所用
    // --------------------------------------------------------- Instance Variables
    private String col1;
    private String col2;
    private String col3;
    private String col4;
    private String col5;
    private String col6;
    private String col7;
    private String col8;
    private String col9;
    private String col10;
            
            ...getter/setter...对象封装成list返回到页面的displaytag中,
    <display:column property="col1" title="总额"  style="width:10%;text-align:left" format="{0,number,#######0.00}"/>
    format失效,估计是要此字段是数字字段才行,我这个col1是String类型的,故失效。
    我在哪里去NumberFormat呢?
      

  6.   

    现在数值显示是没问题了,用到了decorator、format.但是排序却出了问题,数据库中字段类型是number型的可以排序,但是为varchar2型的数值却不能排序了,能有办法解决吗?
      

  7.   

    通常是用数据库查询排序。varchar2类型应该不会有问题。你需要检查一下SQL语句对不对。
      

  8.   

    SELECT a.kehzwm col1,
           a.zhangh col2,--VARCHAR2(20),排序正常
           b.ClerkID col3,--VARCHAR2(10),排序正常
           b.ClerkName col4,--VARCHAR2(50),排序正常
           trunc(b.scale) col5,--varchar2(20),排序异常
           to_number(a.youhll) col6,--NUMBER(9,7),排序正常
           a.kaihrq  col7,--VARCHAR2(8),排序正常
           round(sum(a.zhhuye)/31,2) col8--NUMBER(15,2),排序异常
      FROM table1 a, table2 b
     where a.zhangh = b.Account
       and a.data_his >='20090501'
       and a.data_his <='20090525'
       and substr(a.zhangh, 7, 2) = '53'
       and b.BusiType = '存款类'
     group by a.kehzwm,
              a.zhangh,
              b.ClerkID,
              b.ClerkName,
              b.scale,
              a.youhll,
              a.kaihrq
     having sum(a.zhhuye) / 31 > 0
     order by col8 desc这是我的原始sql,col5,col8两个为什么不能正常排序?有个现象是第一次默认取数据出来是正常排序的,但点击列表头的排序按钮,就排序异常。
    加上foramt、decorator属性也没用,还请高手看看。