public static String divide ( String dividend , String divisor ) { try { BigDecimal bdDividend = new BigDecimal ( dividend ) ; BigDecimal bdDivisor = new BigDecimal ( divisor ) ; try { return bdDividend . divide ( bdDivisor ) . toString ( ) ; } catch ( ArithmeticException ae ) { int scale = Math . max ( bdDividend . scale ( ) , bdDivisor . scale ( ) ) + 1 ; return divide ( dividend , divisor , scale ) ; } } catch ( Exception ex ) { return null ; } }
Get the result of dividend divided by divisor . When the result is indivisible the scale will depends on the scale of dividend and divisor .