Is there a recommended way in Kotlin to validate a...
# getting-started
k
Is there a recommended way in Kotlin to validate a BigDecimal to confirm with e.g.
totalDigits(10) fractionDigits(3)
?
m
No built-in mechanism in the standard lib exists that I know of… do you need to validate a BD in production code or do you need test assertions?
Anyway, BigDecimal provides two methods you could use: • precision() — The precision is the number of digits in the unscaled value • scale() — If zero or positive, the scale is the number of digits to the right of the decimal point. so you could define your extensions on BigDecimal to check for those constraints