public static function format($value, $precision = null, $locale = null)
    {
        if ($precision === null) {
            $precision = self::$default_precision;
        }
        if ($locale) {
            $currentLocale = self::$_locale;
            self::$_locale = $locale;
        }
        if (is_array($value)) {
            foreach ($value as &$val) {
                $val = self::format($val, $precision);
            }
            return $value;
        }

        if (self::$_locale !== i18n::get_locale()) {
            self::initVariables();
        }
        if (self::$_decimals === null) {
            self::initVariables();
        }

        $rawValue = self::unformat($value);

        $formattedValue = number_format(
            $rawValue,
            $precision,
            self::$_decimals,
            self::$_thousands
        );

        if ($locale) {
            self::$_locale = $currentLocale;
        }

        return $formattedValue;
    }