public static function moneyFormat(
        $value,
        $locale = null,
        $display_currency = false,
        $decimal_places = null
    ) {
        if (!function_exists('money_format')) {
            throw new SwatException(
                'moneyFormat() method is not available ' .
                    'on this operating system. See ' .
                    'http://php.net/manual/en/function.money-format.php for ' .
                    'details.'
            );
        }

        if ($locale !== null) {
            $old_locale = setlocale(LC_ALL, 0);
            if (setlocale(LC_ALL, $locale) === false) {
                throw new SwatException(
                    sprintf(
                        'Locale %s passed to the ' .
                            'moneyFormat() method is not valid for this operating ' .
                            'system.',
                        $locale
                    )
                );
            }
        }

        // get character set of the locale that is used
        $character_set = nl_langinfo(CODESET);

        $format_string =
            $decimal_places === null
                ? '%n'
                : '%.' . ((int) $decimal_places) . 'n';

        $output = money_format($format_string, $value);

        if ($display_currency) {
            $lc = localeconv();
            $output .= ' ' . $lc['int_curr_symbol'];
        }

        // convert output to UTF-8
        if ($character_set !== 'UTF-8') {
            $output = iconv($character_set, 'UTF-8', $output);
            if ($output === false) {
                throw new SwatException(
                    sprintf(
                        'Could not convert %s output to UTF-8',
                        $character_set
                    )
                );
            }
        }

        if ($locale !== null) {
            setlocale(LC_ALL, $old_locale);
        }

        return $output;
    }