All Downloads are FREE. Search and download functionalities are using the official Maven repository.

matrix.business.common.utils.BigDecimalUtil Maven / Gradle / Ivy

There is a newer version: 2.1.10
Show newest version
package matrix.business.common.utils;

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

/**
 * BigDecimal工具
 * @author wangcheng
 */
public class BigDecimalUtil {

    /**
     * 元转分
     * @param price 金额
     * @return 金额
     */
    public static Long yuanToCents(BigDecimal price) {
        return price.multiply(BigDecimal.valueOf(100L)).longValue();
    }

    /**
     * 分转元
     * @param price 金额
     * @return 金额
     */
    public static BigDecimal centsToYuan(long price) {
        return BigDecimal.valueOf(price).setScale(2, RoundingMode.HALF_UP).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy