本文整理汇总了PHP中NumberFormatter::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP NumberFormatter::getAttribute方法的具体用法?PHP NumberFormatter::getAttribute怎么用?PHP NumberFormatter::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumberFormatter
的用法示例。
在下文中一共展示了NumberFormatter::getAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explodeTestData
protected function explodeTestData($locale, $currencyCode)
{
// valid values for all currencies
$validDomainValues = [(double) -10, (double) 0, (double) 10];
// invalid values for all currencies
$invalidDomainValues = [-1, 0, 1, null, false, true, "", "123", "foo", [], ['foo' => 'bar'], new \stdClass(), NAN, INF, -INF];
$tmpValid = $validDomainValues;
$tmpInvalid = $invalidDomainValues;
// Build fraction digits test data
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
$formatter->setTextAttribute($formatter::CURRENCY_CODE, $currencyCode);
$fractionDigits = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
$tmpValid[] = (double) (1 + pow(10, -$fractionDigits));
$tmpInvalid[] = (double) (1 + pow(10, -($fractionDigits + 1)));
$pi = pi();
$tmpValid[] = round($pi, $fractionDigits);
if ($fractionDigits > 2) {
$tmpValid[] = round($pi, $fractionDigits - 1);
$tmpValid[] = (double) (1 + pow(10, -($fractionDigits - 1)));
}
$tmpInvalid[] = round($pi, $fractionDigits + 1);
$return = [];
foreach ($tmpValid as $value) {
$return[] = [$value, true];
}
foreach ($tmpInvalid as $value) {
$return[] = [$value, false];
}
return $return;
}
示例2: format
/**
* {@inheritdoc}
*/
public function format(Money $money)
{
$valueBase = (string) $money->getAmount();
$negative = false;
if (substr($valueBase, 0, 1) === '-') {
$negative = true;
$valueBase = substr($valueBase, 1);
}
$fractionDigits = $this->formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
$valueLength = strlen($valueBase);
if ($valueLength > $fractionDigits) {
$subunits = substr($valueBase, 0, $valueLength - $fractionDigits) . '.';
$subunits .= substr($valueBase, $valueLength - $fractionDigits);
} else {
$subunits = '0.' . str_pad('', $fractionDigits - $valueLength, '0') . $valueBase;
}
if ($negative === true) {
$subunits = '-' . $subunits;
}
return $this->formatter->formatCurrency($subunits, $money->getCurrency()->getCode());
}
示例3: parse
/**
* {@inheritdoc}
*/
public function parse($money, $forceCurrency = null)
{
$decimal = $this->formatter->parseCurrency($money, $currency);
if ($decimal === false) {
throw new ParserException('Cannot parse ' . $money . ' to Money. ' . $this->formatter->getErrorMessage());
}
$decimal = (string) $decimal;
if (strpos($decimal, '.') !== false) {
$decimal = str_replace('.', '', $decimal);
} else {
$decimal .= str_pad('', $this->formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS), '0');
}
if (substr($decimal, 0, 1) === '-') {
$decimal = '-' . ltrim(substr($decimal, 1), '0');
} else {
$decimal = ltrim($decimal, '0');
}
if ($forceCurrency === null) {
$forceCurrency = $currency;
}
return new Money($decimal, new Currency($forceCurrency));
}
示例4: check_number_locale
public function check_number_locale()
{
$number_locale = $this->input->post('number_locale');
$fmt = new \NumberFormatter($number_locale, \NumberFormatter::CURRENCY);
$currency_symbol = empty($this->input->post('currency_symbol')) ? $fmt->getSymbol(\NumberFormatter::CURRENCY_SYMBOL) : $this->input->post('currency_symbol');
if ($this->input->post('thousands_separator') == "false") {
$fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
}
$fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $currency_symbol);
$number_local_example = $fmt->format(1234567890.123);
echo json_encode(array('success' => $number_local_example != FALSE, 'number_locale_example' => $number_local_example, 'currency_symbol' => $currency_symbol, 'thousands_separator' => $fmt->getAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL) != ''));
}
示例5: getAttributeDataProvider
public function getAttributeDataProvider()
{
$intlFormatter = new IntlNumberFormatter('en_US', \NumberFormatter::DECIMAL);
$maxIntegerDigits = $intlFormatter->getAttribute(\NumberFormatter::MAX_INTEGER_DIGITS);
return array(array('parse_int_only', 'DECIMAL', 'en_US', 0), array('parse_int_only', null, 'en_US', 0), array('GROUPING_USED', 'decimal', 'en_US', 1), array(\NumberFormatter::DECIMAL_ALWAYS_SHOWN, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MAX_INTEGER_DIGITS, \NumberFormatter::DECIMAL, 'en_US', $maxIntegerDigits), array(\NumberFormatter::MIN_INTEGER_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::INTEGER_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::MAX_FRACTION_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 3), array(\NumberFormatter::MIN_FRACTION_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MAX_FRACTION_DIGITS, \NumberFormatter::CURRENCY, 'en_US', 2), array(\NumberFormatter::MIN_FRACTION_DIGITS, \NumberFormatter::CURRENCY, 'en_US', 2), array(\NumberFormatter::FRACTION_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MULTIPLIER, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::GROUPING_SIZE, \NumberFormatter::DECIMAL, 'en_US', 3), array(\NumberFormatter::ROUNDING_MODE, \NumberFormatter::DECIMAL, 'en_US', 4), array(\NumberFormatter::ROUNDING_INCREMENT, \NumberFormatter::DECIMAL, 'en_US', 0.0), array(\NumberFormatter::FORMAT_WIDTH, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::PADDING_POSITION, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::SECONDARY_GROUPING_SIZE, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::SIGNIFICANT_DIGITS_USED, \NumberFormatter::DECIMAL, 'en_US', 0), array(\NumberFormatter::MIN_SIGNIFICANT_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 1), array(\NumberFormatter::MAX_SIGNIFICANT_DIGITS, \NumberFormatter::DECIMAL, 'en_US', 6));
}
示例6: getMaxDigits
/**
* Numero di decimali impostati per il locale
*
* @return bool|int
*/
public function getMaxDigits()
{
$nft = new NF($this->locale, NF::DECIMAL);
return $nft->getAttribute(NF::MAX_FRACTION_DIGITS);
}