Skip to content

How to check decimal places #454

Closed Answered by CarstenWickner
theseeker58 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @theseeker58,

The fraction could be enforced via the multipleOf keyword (if you don't mind possible trailing zeros), which you can set like this (refer to documentation):

configBuilder.forFields().withNumberMultipleOfResolver(field -> Optional
            .ofNullable(field.getAnnotationConsideringFieldAndGetterIfSupported(Digits.class))
            .map(annotation -> BigDecimal.ONE.divide(BigDecimal.TEN.pow(annotation.fraction()), annotation.fraction(), RoundingMode.FLOOR)).orElse(null));

The maximum number of digits before the decimal separator could similarly be enforced as an exclusiveMaximum (refer to documentation) like this:

configBuilder.forFields().withNumberExclusiveMaximumRes…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@theseeker58
Comment options

Answer selected by theseeker58
Comment options

You must be logged in to vote
2 replies
@CarstenWickner
Comment options

@theseeker58
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants