|
|
@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.math.RoundingMode; |
|
|
import java.text.DecimalFormat; |
|
|
import java.text.DecimalFormat; |
|
|
import java.text.ParseException; |
|
|
import java.text.ParseException; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.text.SimpleDateFormat; |
|
|
@ -151,15 +152,26 @@ public class TrendLogService { |
|
|
|
|
|
|
|
|
//Process the number value. keep 4 ecimal places
|
|
|
//Process the number value. keep 4 ecimal places
|
|
|
if (value instanceof Number) { |
|
|
if (value instanceof Number) { |
|
|
DecimalFormat df = new DecimalFormat("#.####"); // 保留四位小数的格式
|
|
|
Number num = (Number) value; |
|
|
String formatted = df.format((Number)value); |
|
|
double d = num.doubleValue(); |
|
|
value = Double.parseDouble(formatted); |
|
|
|
|
|
}else if (value instanceof Boolean){ |
|
|
// 判断是否为整数(且不是无穷大或 NaN)
|
|
|
if((Boolean)value==true){ |
|
|
if (d == Math.floor(d) && !Double.isInfinite(d) && !Double.isNaN(d)) { |
|
|
value = 1; |
|
|
// 检查是否在 int 范围内
|
|
|
}else{ |
|
|
if (d >= Integer.MIN_VALUE && d <= Integer.MAX_VALUE) { |
|
|
value = 0; |
|
|
value = Integer.valueOf((int) d); |
|
|
|
|
|
} else { |
|
|
|
|
|
value = Integer.valueOf((int) d); // 注意:超范围会溢出!
|
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 非整数:格式化保留最多4位小数
|
|
|
|
|
|
DecimalFormat df = new DecimalFormat("#.####"); |
|
|
|
|
|
df.setRoundingMode(RoundingMode.HALF_UP); |
|
|
|
|
|
String formatted = df.format(d); |
|
|
|
|
|
value = Double.parseDouble(formatted); |
|
|
} |
|
|
} |
|
|
|
|
|
} else if (value instanceof Boolean) { |
|
|
|
|
|
value = (Boolean) value ? 1 : 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 输出数据解读
|
|
|
// 输出数据解读
|
|
|
|