刷卡记录排序和灌溉记录小数点修改

This commit is contained in:
wyw 2024-08-16 05:24:27 +08:00
parent d46835f89a
commit d2d6cd7840
2 changed files with 86 additions and 1 deletions

View File

@ -0,0 +1,84 @@
package com.fastbee.common.utils;
import java.text.DecimalFormat;
/**
* 数字工具类
*/
public class NumberUtils {
/**
* 保留两位小数不足补0
* @param number
* @return
*/
public static float formatFloat(float number) {
return (float) (Math.round(number * 100) / 100.0);
}
/**
* 保留两位小数不足补0
* @param number
* @return
*/
public static Double formatDouble(Double number) {
return (Double) (Math.round(number * 100) / 100.0);
}
/**
* 字符串类型保留两位小数不足补0
* @param str
* @return
*/
public static String formatString(String str) {
if (isNumeric(str)) {
float number = Float.parseFloat(str);
DecimalFormat df = new DecimalFormat("0.00");
return df.format(number);
} else {
return str;
}
}
/**
* 字符串类型保留三位小数不足补0
* @param str
* @return
*/
public static String formatThreeString(String str) {
if (isNumeric(str)) {
float number = Float.parseFloat(str);
DecimalFormat df = new DecimalFormat("0.000");
return df.format(number);
} else {
return str;
}
}
/**
* 字符串类型保留三位小数不足补0
* @param str
* @param format 样式例如0.000
* @return
*/
public static String formatStringByFormat(String str,String format) {
if (isNumeric(str)) {
float number = Float.parseFloat(str);
DecimalFormat df = new DecimalFormat(format);
return df.format(number);
} else {
return str;
}
}
/**
* 正则判断是否为数字
* @param str
* @return
*/
public static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?");
}
}

View File

@ -10,6 +10,7 @@ import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.alibaba.excel.util.NumberUtils;
import com.fastbee.common.core.page.PageDomain;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.core.page.TableSupport;
@ -117,7 +118,7 @@ public class MaGuangaiRecordServiceImpl implements IMaGuangaiRecordService
record.setCurEle(item.get("cur_ele").toString());
record.setCardId(item.get("card_id").toString());
record.setAreaCode(item.get("area_code").toString());
record.setUserBalance(item.get("user_balance").toString());
record.setUserBalance(com.fastbee.common.utils.NumberUtils.formatFloat(Float.parseFloat(item.get("user_balance").toString())/100)+"");
record.setCurFlow(item.get("cur_flow").toString());
record.setCurEle(item.get("cur_ele").toString());
record.setStatus(Integer.parseInt(item.get("status").toString()));