Jay
2024-11-01 03e8aca3ad6201c0d74e00d4c8d7367cdaaa54f9
提交 | 用户 | 时间
e7c126 1 package com.iailab.framework.excel.core.convert;
H 2
3 import com.alibaba.excel.converters.Converter;
4 import com.alibaba.excel.enums.CellDataTypeEnum;
5 import com.alibaba.excel.metadata.GlobalConfiguration;
6 import com.alibaba.excel.metadata.data.WriteCellData;
7 import com.alibaba.excel.metadata.property.ExcelContentProperty;
8
9 import java.math.BigDecimal;
10 import java.math.RoundingMode;
11
12 /**
13  * 金额转换器
14  *
15  * 金额单位:分
16  *
17  * @author iailab
18  */
19 public class MoneyConvert implements Converter<Integer> {
20
21     @Override
22     public Class<?> supportJavaTypeKey() {
23         throw new UnsupportedOperationException("暂不支持,也不需要");
24     }
25
26     @Override
27     public CellDataTypeEnum supportExcelTypeKey() {
28         throw new UnsupportedOperationException("暂不支持,也不需要");
29     }
30
31     @Override
32     public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty,
33                                                     GlobalConfiguration globalConfiguration) {
34         BigDecimal result = BigDecimal.valueOf(value)
35                 .divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
36         return new WriteCellData<>(result.toString());
37     }
38
39 }