function currency_side() { $config = get_instance()->config; $fmt = new \NumberFormatter($config->item('number_locale'), \NumberFormatter::CURRENCY); $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); return !preg_match('/^¤/', $fmt->getPattern()); }
public static function moneda($entero, $localidad = null, $codigo = null) { if (empty($entero)) { return $entero; } $localidad = empty($localidad) ? self::LOCALIDAD_RD : $localidad; $codigo = empty($codigo) ? self::CODIGO_RD : $codigo; $sufijo = $localidad == 'es_DO' ? 'RD' : ''; $fmt = new NumberFormatter($localidad, NumberFormatter::CURRENCY); //$fmt->setTextAttribute(NumberFormatter::CURRENCY_CODE, 'DOP'); $fmt->setPattern(str_replace('¤#', '¤ #', $fmt->getPattern())); return $sufijo . $fmt->formatCurrency($entero, $codigo); //setlocale(LC_MONETARY, $localidad); //return money_format('%i', $entero) . "\n"; }
/** * Pattern espositivo della valuta * * @return bool|string */ public function getPattern() { $nft = new NF($this->locale, NF::CURRENCY); return $nft->getPattern(); }
/** * Mostra o Valor no real Formatado * @param float $number * @param boolean $fixed * @param boolean $symbol * @param integer $decimals * @return string */ public static function nReal($number, $decimals = 2, $symbol = true, $fixed = true) { if (is_null($number) || empty(self::onlyNumbers($number))) { return ''; } $formater = new \NumberFormatter("pt-BR", \NumberFormatter::CURRENCY); $formater->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $fixed ? $decimals : 1); if ($decimals === false) { $decimals = 2; preg_match_all('/[0-9][^0-9]([0-9]+)/', $number, $matches); if (!empty($matches[1])) { $decimals = strlen(rtrim($matches[1][0], 0)); } } $formater->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals); if (!$symbol) { $pattern = preg_replace("/[¤]/", '', $formater->getPattern()); $formater->setPattern($pattern); } else { // ESPAÇO DEPOIS DO SIMBOLO $pattern = str_replace("¤", "¤ ", $formater->getPattern()); $formater->setPattern($pattern); } return $formater->formatCurrency($number, $formater->getTextAttribute(\NumberFormatter::CURRENCY_CODE)); }