package com.ycwl.basic.utils;


import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Author: songmingsong
 * @CreateTime: 2024-12-06
 * @Description: 小数转换
 * @Version: 1.0
 */
public class BigDecimalUtil {
    public static int convertToCents(BigDecimal price) {
        if (price == null) {
            throw new IllegalArgumentException("Price cannot be null");
        }
        return price
                .setScale(2, RoundingMode.HALF_UP) // 保留两位小数
                .multiply(new BigDecimal(100))    // 转换为分
                .intValue();
    }

}
