Common code for Java and Scala big decimal conversion.