package com.bcxin.ars.strategy.ministerial;

import com.abcxin.smart.validator.annotation.MinisterialAttr;

import java.lang.reflect.Field;
import java.math.BigDecimal;

/**
 * 小数转百分比
 * @author zhangyutong
 */
public class StockDataFormatStrategy implements MinDataFormatStrategy {
    @Override
    public String format(Field columnField, Object data) {

        if(data == null){
            MinisterialAttr resource = columnField.getAnnotation(MinisterialAttr.class);
            return resource.defaultValue();
        }

        double doubleValue = Double.parseDouble(data.toString());
        BigDecimal bigDecimalValue = new BigDecimal(doubleValue);
        BigDecimal multiplyValue = bigDecimalValue.multiply(BigDecimal.valueOf(100));
        String multiplyStringValue = String.valueOf(multiplyValue);
        return multiplyStringValue.substring(0, multiplyStringValue.lastIndexOf(".") + 3);
    }
}
