|
|
|
@ -646,7 +646,7 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
|
// 尝试解析为数字 |
|
|
|
BigDecimal number = new BigDecimal(text.trim()); |
|
|
|
return formatNumber(number, element.getDecimalPlaces(), |
|
|
|
element.getShowDecimalPlaces(), element.getThousandsSeparator()); |
|
|
|
element.getShowDecimalPlaces(), element.getThousandsSeparator(), element.getRoundHalfUp()); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
log.debug("文本无法解析为数字,保持原样: {}", text); |
|
|
|
return text; |
|
|
|
@ -655,6 +655,14 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
|
|
|
|
|
@Override |
|
|
|
public String formatNumber(Object value, Integer decimalPlaces, Boolean showDecimalPlaces, Boolean thousandsSeparator) { |
|
|
|
return formatNumber(value, decimalPlaces, showDecimalPlaces, thousandsSeparator, true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 格式化数字数据(支持四舍五入或截断) |
|
|
|
*/ |
|
|
|
private String formatNumber(Object value, Integer decimalPlaces, Boolean showDecimalPlaces, |
|
|
|
Boolean thousandsSeparator, Boolean roundHalfUp) { |
|
|
|
if (value == null) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
@ -683,8 +691,9 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
|
// 创建格式化器 |
|
|
|
DecimalFormat formatter = createNumberFormatter(scale, Boolean.TRUE.equals(thousandsSeparator)); |
|
|
|
|
|
|
|
// 设置舍入模式 |
|
|
|
formatter.setRoundingMode(RoundingMode.HALF_UP); |
|
|
|
// 设置舍入模式:默认四舍五入;取消勾选时按小数位截断 |
|
|
|
boolean useHalfUp = roundHalfUp == null || Boolean.TRUE.equals(roundHalfUp); |
|
|
|
formatter.setRoundingMode(useHalfUp ? RoundingMode.HALF_UP : RoundingMode.DOWN); |
|
|
|
|
|
|
|
return formatter.format(number); |
|
|
|
|
|
|
|
@ -1231,6 +1240,7 @@ public class LabelDataProcessorServiceImpl implements LabelDataProcessorService |
|
|
|
copy.setDecimalPlaces(original.getDecimalPlaces()); |
|
|
|
copy.setShowDecimalPlaces(original.getShowDecimalPlaces()); |
|
|
|
copy.setThousandsSeparator(original.getThousandsSeparator()); |
|
|
|
copy.setRoundHalfUp(original.getRoundHalfUp()); |
|
|
|
copy.setDigits(original.getDigits()); |
|
|
|
copy.setStep(original.getStep()); |
|
|
|
|
|
|
|
|