02/04/2022, 9:59 AM
Is there a recommended way in Kotlin to validate a BigDecimal to confirm with e.g.
totalDigits(10) fractionDigits(3)

Matteo Mirk

02/11/2022, 10:01 AM
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