Formats money value based in a country code

@param float  $val     Value to be formatted
@param string $country Country whose money conventions will be used

@return string
770386
public static function money($val, $country = 'BR')
    {
        switch ($country) {
            case 'US':
                $arr = ['US$', ',', '.'];
                break;
            case 'BR':
            default:
                $arr = ['R$', '.', ','];
        }
        return ($arr[0] . ' ' . number_format($val, 2, $arr[2], $arr[1]));
    }
271386
public function localizeMoneyFilter(Money $money, string $locale = null): string
    {
        $formatter      = twig_get_number_formatter($locale, 'currency');
        $moneyFormatter = new IntlMoneyFormatter($formatter, $this->currencies);

        /** @var \Money\Money $formattingMoney */
        $formattingMoney = $money->getValueObject();

        return $moneyFormatter->format($formattingMoney);
    }
619572
public function format($value, $code = null, $include_symbol = true)
    {
        // Get default currency if one is not set
        $code = $code ?: $this->config('default');

        // Remove unnecessary characters
        $value = preg_replace('/[\s\',!]/', '', $value);

        // Check for a custom formatter
        if ($formatter = $this->getFormatter()) {
            return $formatter->format($value, $code);
        }

        // Get the measurement format
        $format = $this->getCurrencyProp($code, 'format');

        // Value Regex
        $valRegex = '/([0-9].*|)[0-9]/';

        // Match decimal and thousand separators
        preg_match_all('/[\s\',.!]/', $format, $separators);

        if ($thousand = array_get($separators, '0.0', null)) {
            if ($thousand == '!') {
                $thousand = '';
            }
        }

        $decimal = array_get($separators, '0.1', null);

        // Match format for decimals count
        preg_match($valRegex, $format, $valFormat);

        $valFormat = array_get($valFormat, 0, 0);

        // Count decimals length
        $decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;

        // Do we have a negative value?
        if ($negative = $value < 0 ? '-' : '') {
            $value = $value * -1;
        }

        // Format the value
        $value = number_format($value, $decimals, $decimal, $thousand);

        // Apply the formatted measurement
        if ($include_symbol) {
            $value = preg_replace($valRegex, $value, $format);
        }

        // Return value
        return $negative . $value;
    }
877840
public function convertAndFormat($money, $language = null, $currency = null)
    {
        if (!$currency) {
            $currency = $this->currencyCode;
        }

        $convertedMoney = $money->convertToCurrency($currency);

        return $this->intlFormatter($language)->format($convertedMoney);
    }
829604
static String formatPriceString(double amount, @NonNull Currency currency) {
        double majorUnitAmount = amount / Math.pow(10, currency.getDefaultFractionDigits());
        NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
        try {
            DecimalFormatSymbols decimalFormatSymbols = ((java.text.DecimalFormat) currencyFormat)
                    .getDecimalFormatSymbols();
            decimalFormatSymbols.setCurrencySymbol(currency.getSymbol(Locale.getDefault()));
            ((java.text.DecimalFormat) currencyFormat)
                    .setDecimalFormatSymbols(decimalFormatSymbols);
            return currencyFormat.format(majorUnitAmount);
        } catch (ClassCastException e) {
            return currencyFormat.format(majorUnitAmount);
        }
    }
905433
protected function formatValue($format, $value)
    {
        switch ($format) {
            case Format::DATE:
            case Format::DATETIME:
                if ($value instanceof \DateTime) {
                    return $value->format('c');
                }
                break;

            case Format::FLOAT2:
            case Format::MONEY2:
                return floatval(sprintf("%.2f", $value));

            case Format::PCT2:
                return floatval(sprintf('%.2f', $value*100));

            case Format::PCT:
                return intval(sprintf('%d', $value*100));

            case Format::INTEGER:
            case Format::MONEY:
                return intval(sprintf("%d", $value));
        }

        return $value;
    }
1186816
public static function getCode($val, $alpha3 = false)
    {
        if (self::$_countryFlip === array()) {
            self::$_countryFlip = array_flip(self::$_countries);
        }
        if (!array_key_exists($val, self::$_countryFlip)) {
            return null;
        }
        $result = self::$_countryFlip[$val];
        if ($alpha3) {
            return self::$_tlcMap[$result];
        }
        return $result;
    }
742888
public function get($val)
    {
        // If we already have the code, just return that
        if (is_numeric($val)) {
            return $val;
        }

        if (array_key_exists($val, $this->formats)) {
            return $this->formats[$val];
        }

        return null;
    }
647594
public static function money($value=0, bool $cents=false, $separator='', bool $no00=false) {
		ref\format::money($value, $cents, $separator, $no00);
		return $value;
	}
311554
public function getCodeFromCountry($country)
    {
        $output = 'OTH';
        if (array_key_exists($country, $this->countriesMapping)) {
            $output = $this->countriesMapping[$country];
        }

        return $output;
    }
328190
public function ValidTax($country = null, $region = null)
    {
        if (empty($country)) {
            // First try and get the locale from the member
            $member = Security::getCurrentUser();

            if ($member && $member->getLocale()) {
                $country = $member->getLocale();
            }
        }

        if (empty($country)) {
            $country = i18n::get_locale();
        }

        if (strlen($country) > 2) {
            $country = Locale::getRegion($country);
        }

        $filter = [
            'Global' => 1,
            "Zones.Regions.CountryCode" => $country
        ];

        $rates = $this
            ->Rates()
            ->filterAny($filter);

        if (isset($region)) {
            $rates = $rates->filter("Zones.Regions.Code", $region);
        }

        return $rates->first();
    }
1345943
def _format_value(self, val):
        
        name = self.name + ":"
        if not self.multiline or "\n" not in val:
            val = u"{0} {1}".format(name.ljust(self._text_prefix_len), val)
        else:
            spacer = "\n" + " " * (self._text_prefix_len + 1)
            val = u"{0}{1}{2}".format(name, spacer, spacer.join(val.split("\n")))

        return val
749199
function formatarTelefone($valor)
    {
        if (strlen($valor) < 10) {
            return $this->formatarValor($valor, '####-####');
        }

        if (strlen($valor) == 10) {
            return $this->formatarValor($valor, '(##) ####-####');
        }

        return $this->formatarValor($valor, '(##) #####-####');
    }
449364
protected function formatValue($format, $value)
    {
        // TODO : Put in parameters
        $decimals = 2;
        $dec_point = ',';
        $thousands_sep = ' ';

        switch ($format) {
            case Format::DATE:
                if ($value instanceof \DateTime) {
                    return $value->format('d/m/Y');
                }
                break;

            case Format::DATETIME:
                if ($value instanceof \DateTime) {
                    return $value->format('d/m/Y H:i:s');
                }
                break;

            case Format::FLOAT2:
                return str_replace($dec_point."00", "",number_format(floatval($value), $decimals, $dec_point, $thousands_sep));

            case Format::INTEGER:
                return number_format(intval($value), 0, $dec_point, $thousands_sep);

            case Format::PCT:
                return $this->formatValue(Format::INTEGER, $value*100)."%";

            case Format::PCT2:
                return $this->formatValue(Format::FLOAT2, $value*100)."%";

            case Format::MONEY:
                return $this->formatValue(Format::INTEGER, $value)."€";

            case Format::MONEY2:
                return $this->formatValue(Format::FLOAT2, $value)."€";
        }

        return $value;
    }
1344301
function formatarValor($valor, $formato)
    {
        $tamanhoValor = strlen($valor);
        $tamanhoFormato = substr_count($formato, '#');

        if ($tamanhoValor < $tamanhoFormato) {
            $diferenca = $tamanhoFormato - $tamanhoValor;
            $valor = $valor . str_repeat('#', $diferenca);
        }

        if ($tamanhoValor > $tamanhoFormato) {
            $valor = substr($valor, 0, $tamanhoFormato);
        }

        $formato = str_replace('#', '%s', $formato);
        return vsprintf($formato, str_split($valor));
    }
90462
protected function money(int $val): Money
    {
        if (!$this->currency) {
            throw new UnsetCurrencyException('The currency is not set on this stock movement');
        }

        return new Money($val, new Currency($this->currency));
    }
741237
public String formatValue(ReportValue val) {
      if (log.isLoggable(Level.FINE) || debug) {
         log.fine("raw: " + val + ", formatted: " + doFormatValue(val));
      }
      return doFormatValue(val);
   }