赞
踩
1.String.format保留2位小数
String.format("%.2f", "2.25558")
2.计算年比和环比
- /**
- *
- *环比
- * @param nowTotal
- * @param lastTotal
- * @return
- */
- private String getCompareRate(Float nowTotal, Float lastTotal) {
- if (nowTotal.equals(lastTotal)) {
- return "0.0%";
- }
- if(lastTotal==0.0){
- return "-";
- }
- return String.format("%.2f", ((nowTotal - lastTotal) / lastTotal * 100)) + "%";
- }
-
- /**
- *
- *同比
- * @param nowTotal
- * @param lastTotal
- * @return
- */
- private String getCompareYoyRate(Float nowTotal, Float lastTotal) {
- if (nowTotal.equals(lastTotal)) {
- return "0.0%";
- }
- if(lastTotal==0.0){
- return "-";
- }
- return String.format("%.2f", ((nowTotal - lastTotal) / nowTotal * 100)) + "%";
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。