private String format(final String original) {
        final String[] parts = original.split("\\" + mDecimalSeparator, -1);
        String number = parts[0] // since we split with limit -1 there will always be at least 1 part
                .replaceAll(mNumberFilterRegex, "")
                .replaceFirst(LEADING_ZERO_FILTER_REGEX, "");

        // only add grouping separators for non custom decimal separator
        if (!hasCustomDecimalSeparator) {
            // add grouping separators, need to reverse back and forth since Java regex does not support
            // right to left matching
            number = StringUtils.reverse(
                    StringUtils.reverse(number).replaceAll("(.{3})", "$1" + GROUPING_SEPARATOR));
            // remove leading grouping separator if any
            number = StringUtils.removeStart(number, String.valueOf(GROUPING_SEPARATOR));
        }

        // add fraction part if any
        if (parts.length > 1) {
            if (parts[1].length() > 2) {
                number += mDecimalSeparator + parts[1].substring(parts[1].length() - 2, parts[1].length());
            } else {
                number += mDecimalSeparator + parts[1];
            }
        }

        return number;
    }
private String format ( final String original ) { final String [ ] parts = original . split ( "\\" + mDecimalSeparator , - 1 ) ; String number = parts [ 0 ] . replaceAll ( mNumberFilterRegex , "" ) . replaceFirst ( LEADING_ZERO_FILTER_REGEX , "" ) ; if ( ! hasCustomDecimalSeparator ) { number = StringUtils . reverse ( StringUtils . reverse ( number ) . replaceAll ( "(.{3})" , "$1" + GROUPING_SEPARATOR ) ) ; number = StringUtils . removeStart ( number , String . valueOf ( GROUPING_SEPARATOR ) ) ; } if ( parts . length > 1 ) { if ( parts [ 1 ] . length ( ) > 2 ) { number += mDecimalSeparator + parts [ 1 ] . substring ( parts [ 1 ] . length ( ) - 2 , parts [ 1 ] . length ( ) ) ; } else { number += mDecimalSeparator + parts [ 1 ] ; } } return number ; }
Add grouping separators to string

@param original original string, may already contains incorrect grouping separators
@return string with correct grouping separators