如何在Java程序的sql中去掉小数点后多余的0
读取数据的语句如下:publicString[]monthCheckOut(Stringnum){Stringvalues[]={"--","--","--","--",...
读取数据的语句如下:
public String[] monthCheckOut(String num) { String values[]={"--","--","--","--","--"}; String sqls[]={"select count(*) from tb_order_form where num like '"+num+"%'","select sum(money) from tb_order_form where num like '"+num+"%'","select avg(money) from tb_order_form where num like '"+num+"%'", "select max(money) from tb_order_form where num like '" + num + "%'", "select min(money) from tb_order_form where num like '" + num + "%'"}; for(int i=0;i<sqls.length;i++){ Object value = super.selectOnlyValue(sqls[i]); if(value!=null){ String v = value.toString(); if(!v.equals("0")) values[i] = v;// TODO Auto-generated method stub } } return values; }
其中count,sum,max,min读取出来的数都是不带小数点的,只有avg带四个小数点,我想只留两个,网上说用select cast(round(1.00/3,2) as decimal(18,2)),但是应该插到哪呢? 展开
public String[] monthCheckOut(String num) { String values[]={"--","--","--","--","--"}; String sqls[]={"select count(*) from tb_order_form where num like '"+num+"%'","select sum(money) from tb_order_form where num like '"+num+"%'","select avg(money) from tb_order_form where num like '"+num+"%'", "select max(money) from tb_order_form where num like '" + num + "%'", "select min(money) from tb_order_form where num like '" + num + "%'"}; for(int i=0;i<sqls.length;i++){ Object value = super.selectOnlyValue(sqls[i]); if(value!=null){ String v = value.toString(); if(!v.equals("0")) values[i] = v;// TODO Auto-generated method stub } } return values; }
其中count,sum,max,min读取出来的数都是不带小数点的,只有avg带四个小数点,我想只留两个,网上说用select cast(round(1.00/3,2) as decimal(18,2)),但是应该插到哪呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询