private static BigDecimal toBigDecimal(Memory value) {
        try {
            switch (value.type){
                case DOUBLE: return BigDecimal.valueOf(value.toDouble());
                case INT: return BigDecimal.valueOf(value.toLong());
                default:
                    return new BigDecimal(value.toString());
            }
        } catch (NumberFormatException ex) {
            return BigDecimal.ZERO;
        } catch (IllegalArgumentException ex) {
            return BigDecimal.ZERO;
        }
    }
bcmath extension
http://www.php.net/manual/ru/book.bc.php
exts/jphp-zend-ext/src/main/java/org/develnext/jphp/zend/ext/standard/BCMathFunctions.java