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

com.github.houbb.valid.jsr.constraint.DigitsBigDecimalConstraint Maven / Gradle / Ivy

package com.github.houbb.valid.jsr.constraint;

import com.github.houbb.heaven.annotation.ThreadSafe;

import java.math.BigDecimal;

/**
 * {@link javax.validation.constraints.Digits} 约束注解实现
 * @author binbin.hou
 * @since 0.0.3
 * @see BigDecimal
 */
@ThreadSafe
class DigitsBigDecimalConstraint extends AbstractDigitsConstraint {

    public DigitsBigDecimalConstraint(int integer, int fraction) {
        super(integer, fraction);
    }

    public DigitsBigDecimalConstraint(int integer) {
        super(integer);
    }

    /**
     * 用整体精度位数-小数位数
     * @param value 值
     * @return 整数位数
     */
    @Override
    protected int getIntegerDigits(BigDecimal value) {
        return value.precision() - value.scale();
    }

    @Override
    protected int getFractionDigits(BigDecimal value) {
        return value.scale();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy