package com.qmth.boot.tools.excel.convertor.impl;

import com.qmth.boot.tools.excel.convertor.ValueConvertor;
import com.qmth.boot.tools.excel.model.FieldParam;
import org.apache.poi.ss.usermodel.Cell;

import java.math.BigDecimal;

public class BigDecimalConvertor implements ValueConvertor<BigDecimal> {

    public static final BigDecimalConvertor instance = new BigDecimalConvertor();

    @Override
    public BigDecimal parse(String value, FieldParam param) throws Exception {
        return new BigDecimal(value);
    }

    @Override
    public void format(BigDecimal object, FieldParam param, Cell cell) throws Exception {
        cell.setCellValue(object.stripTrailingZeros().toString());
    }
}
