package com.qmth.teachcloud.common.util.excel.convertor.impl;

import java.text.DecimalFormat;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;

import com.qmth.teachcloud.common.util.excel.convertor.ValueConvertor;
import com.qmth.teachcloud.common.util.excel.model.FieldParam;

public class FloatConvertor implements ValueConvertor<Float> {

    public static final FloatConvertor instance = new FloatConvertor();

    @Override
    public Float parse(String value, FieldParam param) throws Exception {
        return Float.parseFloat(value);
    }

    @Override
    public void format(Float object, FieldParam param, Cell cell) throws Exception {
        if (StringUtils.isNotBlank(param.getAnnotation().pattern())) {
            cell.setCellValue(new DecimalFormat(param.getAnnotation().pattern()).format(object));
        } else {
            cell.setCellValue(object);
        }
    }
}
