


package com.jwipc.prop;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.math.RoundingMode;

/**
 * <p> </p>
 *
 * @author shenyang.ou
 * @version 1.0
 * @since JDK 17
 */
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = PriceHandle.PREFIX)
public class PriceHandle {
    public final static String PREFIX = "price-handle";
    /**
     * 保留小数点
     */
    private Integer precision;
    /**
     * 小数点位数不足是否补0
     */
    private Boolean repair;
    /**
     * 是否需要千分位
     */
    private Boolean thousand;
    /**
     * 截取方式 0-四舍五入；1-向下舍入（截断）
     */
    private Integer cutType;

    /**
     * 获取BigDecimal的舍入模式
     *
     * @return
     */
    public RoundingMode getRoundingMode() {
        return this.cutType == 0 ? RoundingMode.HALF_UP : RoundingMode.HALF_DOWN;
    }
}
