本文整理汇总了PHP中NumberFormatter::format方法的典型用法代码示例。如果您正苦于以下问题:PHP NumberFormatter::format方法的具体用法?PHP NumberFormatter::format怎么用?PHP NumberFormatter::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumberFormatter
的用法示例。
在下文中一共展示了NumberFormatter::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: porExtenso
/**
* Retorna número no formato brasileiro (locale: pt_BR, currency: BRL) por extenso
*
* @param number $number
* @return string no formato brasileiro (locale: pt_BR, currency: BRL) por extenso
*/
public function porExtenso($number)
{
if (!is_numeric($number)) {
return false;
}
$numero_extenso = '';
$arr = explode(".", $number);
$inteiro = $arr[0];
if (isset($arr[1])) {
$decimos = strlen($arr[1]) == 1 ? $arr[1] . '0' : $arr[1];
}
$fmt = new \NumberFormatter('br', \NumberFormatter::SPELLOUT);
if (is_array($arr)) {
$numero_extenso = $fmt->format($inteiro) . ' reais';
if (isset($decimos) && $decimos > 0) {
$numero_extenso .= ' e ' . $fmt->format($decimos) . ' centavos';
}
}
return $numero_extenso;
}
示例2: serializeFloatType
/**
* @param VisitorInterface $visitor
* @param FloatType $data
* @param array $type
* @param Context $context
*
* @return mixed|void
*/
public function serializeFloatType(VisitorInterface $visitor, FloatType $data, array $type, Context $context)
{
$numberFormatter = new \NumberFormatter($this->getLocale($type), $this->getFormat($type));
if ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData) {
return $visitor->visitSimpleString($numberFormatter->format($data->getValue()), $type, $context);
}
return $visitor->visitString($numberFormatter->format($data->getValue()), $type, $context);
}
示例3: convert
public function convert()
{
$formatter = new \NumberFormatter($this->locale, \NumberFormatter::PATTERN_DECIMAL);
foreach ($this->binaryPrefixes as $size => $unitPattern) {
if ($size <= $this->number) {
$value = $this->number >= self::CONVERT_THRESHOLD ? $this->number / (double) $size : $this->number;
$formatter->setPattern($unitPattern);
return $formatter->format($value);
}
}
return $formatter->format($this->number);
}
示例4: render
public function render(\Erebot\IntlInterface $translator)
{
$locale = $translator->getLocale(\Erebot\IntlInterface::LC_NUMERIC);
$formatter = new \NumberFormatter($locale, \NumberFormatter::IGNORE);
$result = (string) $formatter->format($this->value, \NumberFormatter::TYPE_INT32);
return $result;
}
示例5: bytesToHuman
public function bytesToHuman($bytes, $precision = 2)
{
$suffixes = ['bytes', 'kB', 'MB', 'GB', 'TB'];
$formatter = new \NumberFormatter($this->translator->getLocale(), \NumberFormatter::PATTERN_DECIMAL, 0 === $precision ? '#' : '.' . str_repeat('#', $precision));
$exp = floor(log($bytes, 1024));
return $formatter->format($bytes / pow(1024, floor($exp))) . ' ' . $this->translator->trans($suffixes[$exp]);
}
示例6: decimalNumber
/**
* Formatação de numero decimal
* @param float/integer $value
* @param integer $precision
* @param string $language
* @return float
*/
public static function decimalNumber($value, $precision = 2, $language = 'pt_BR')
{
$valDecimal = new \NumberFormatter($language, \NumberFormatter::DECIMAL);
$valDecimal->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $precision);
$valDecimal->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $precision);
return $valDecimal->format((double) $value, \NumberFormatter::TYPE_DOUBLE);
}
示例7: formatI18nDecimal
/**
* localized format for money with the NumberFormatter class in Decimal mode
* without currency symbol
* like 1.234,56
*
* @param Money $money
* @param null $locale
* @return bool|string
*/
public function formatI18nDecimal(Money $money, $locale = null)
{
if ($locale === null) {
$locale = $this->locale;
}
$formatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
return $formatter->format($money->getConvertedAmount());
}
示例8: porExtenso
/**
* Retorna número por extenso
* @param int $number
* @return string número por extenso
*/
public function porExtenso($number)
{
if (!is_numeric($number)) {
return false;
}
$fmt = new \NumberFormatter('br', \NumberFormatter::SPELLOUT);
return $fmt->format($number);
}
示例9: spell
/**
* 数值转为中文拼读
*/
public static function spell($number, $capital = false)
{
$formatter = new \NumberFormatter('zh_CN', \NumberFormatter::SPELLOUT);
$sentence = $formatter->format($number);
if ($capital) {
$sentence = self::mbStrtr($sentence, self::$chars, self::$caps);
}
return $sentence;
}
示例10: render
public function render(\Erebot\IntlInterface $translator)
{
$locale = $translator->getLocale(\Erebot\IntlInterface::LC_NUMERIC);
$formatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 100);
$result = (string) $formatter->format($this->value);
return $result;
}
示例11: Repeat
public static function Repeat($times)
{
$list = new ArrayList();
$formatter = new NumberFormatter('en-NZ', NumberFormatter::SPELLOUT);
for ($i = 1; $i <= $times; $i++) {
$list->push(array('Num' => $i, 'Word' => ucwords(strtolower($formatter->format($i)))));
}
return $list;
}
示例12: format
/**
* {@inheritdoc}
*/
public function format($value)
{
$uiLocale = $this->getUiLocale();
if (null === $uiLocale) {
return $value;
}
$numberFormatter = new \NumberFormatter($uiLocale, \NumberFormatter::DECIMAL);
$numberFormatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->getDecimalCount($value));
return $numberFormatter->format($value);
}
示例13: smarty_function_numberDecimal
function smarty_function_numberDecimal(array $params, Smarty_Internal_Template $template)
{
$value = $params['value'];
if (!is_numeric($value)) {
throw new CM_Exception_Invalid('Invalid non-numeric value');
}
/** @var CM_Frontend_Render $render */
$render = $template->getTemplateVars('render');
$formatter = new NumberFormatter($render->getLocale(), NumberFormatter::DECIMAL);
return $formatter->format($value);
}
示例14: format
/**
* Format the specified number to a string with the specified number of
* fractional digits.
*
* @param
* double d
* The number to format.
* @param
* int digits
* The number of fractional digits.
* @return string The number formatted as a string.
*/
public function format($d, $digits)
{
$this->synchronized(function ($thread) {
if (is_infinite($d) || is_nan($d)) {
return "0";
}
$this->numberFormatter->setAttribute(\NumberFormatter::GROUPING_USED, false);
$this->numberFormatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $digits);
return $this->numberFormatter->format($d);
});
}
示例15: entityToHtml
private function entityToHtml($ent = null, $html = '')
{
//debug($ent);
//die();
$spellf = new \NumberFormatter("es", \NumberFormatter::SPELLOUT);
$totalImporte = array_sum(array_column($ent->cuotas_polizas, 'pagado'));
$html = str_replace("[NroRecibo]", $ent->id + $this->primerRecibo, $html);
$html = str_replace("[Fecha]", $ent->created, $html);
$html = str_replace("[Cliente]", $ent->client->razonSocial, $html);
$html = str_replace("[TotalPalabras]", $spellf->format($ent->cuotas_polizas[0]['pagado']), $html);
return $html;
}