自动显示小数点或者不显示
郁闷 昨晚收到客户的更改通知
Description
........
Lastly, I actually like your printout lay out, It lookpretty good,
but it can be better.Please see attachment "Quotation (1).pdf"
I need to show the customer tel, fax,and E-mail as well as
the attention name. Under "Size Column",can you set the
decimal by auto?For example from the attachment,
the first item I have72.0 x 51.0 x 4.0. can you
only show 72 x 51 x 4?I am not asking you to set it
as fix as no decimal at all because sometimes I would
have 72.5 x 65.5 x 6.75.I am just wondering if you
can set the decimal by auto?
.......
?
?
这问题蛋痛了,实体类的代码如下
?
@Transientpublic String getSizeDisplay() {??????? return String.format("%s(%.2f x %.2f x %.2f)", model, size, size2,size3);}?
郁闷了 都写死了
?
然后自己写了一个内部类
public String getConvertValue(Double size) { ??????????????? String sizeToString = size + "";?int indexPoint = sizeToString.indexOf(".");?String getPointValue = sizeToString.substring(indexPoint + 1,sizeToString.length());?int getPointValueToInteger = Integer.parseInt(getPointValue);?return getPointValueToInteger == 0 ? String.valueOf(Math.round(size)): sizeToString;}
?哈哈 解决了上面的问题了 嘿嘿
?
刚刚又想到了 上面的问题 不能解决实际 如果客户输入的是70.0089 输出是70.0089 客户需要的是2位有效小数点 我又想了一个办法看代码,可能我的代码写得不好,没办法 我是实习生 还没有毕业,各位大虾别骂我
?
public String getConvertValue2(Double size) {String sizeToString = String.format("%.2f", size);int indexPoint = sizeToString.indexOf(".");String getPointValue = sizeToString.substring(indexPoint + 1,indexPoint + 2);String getPointValue2 = sizeToString.substring(indexPoint + 2,indexPoint + 3);int getPointValueToInteger = Integer.parseInt(getPointValue);??????????????? int getPointValueToInteger2 = Integer.parseInt(getPointValue2);String result = sizeToString.substring(0, getPointValueToInteger2==0????????????????????????????????????????? indexPoint + 2:indexPoint + 3);return getPointValueToInteger == 0 && getPointValueToInteger2 == 0 ? String????????.valueOf(Math.round(size)) : result;}?
上面解决了那个问题。再次声明我的代码写得不好,请各位大虾别骂我。我只是是实习生 还没有毕业的。哎
?
使用DecimalFormat更方便
?
public String getSizeDisplay(double size) { DecimalFormat format = new DecimalFormat("###0.##"); return String.format("%s", format.format(size));}?
?
?