Пример #1
0
 /**
  * Creates a number format object from the provided definition.
  *
  * @param array  $definition The number format definition.
  * @param string $locale     The locale of the number format definition.
  *
  * @return NumberFormat
  */
 protected function createNumberFormatFromDefinition(array $definition, $locale)
 {
     if (!isset($definition['decimal_separator'])) {
         $definition['decimal_separator'] = '.';
     }
     if (!isset($definition['grouping_separator'])) {
         $definition['grouping_separator'] = ',';
     }
     if (!isset($definition['plus_sign'])) {
         $definition['plus_sign'] = '+';
     }
     if (!isset($definition['minus_sign'])) {
         $definition['minus_sign'] = '-';
     }
     if (!isset($definition['percent_sign'])) {
         $definition['percent_sign'] = '%';
     }
     $numberFormat = new NumberFormat();
     $numberFormat->setLocale($locale);
     $numberFormat->setNumberingSystem($definition['numbering_system']);
     $numberFormat->setDecimalSeparator($definition['decimal_separator']);
     $numberFormat->setGroupingSeparator($definition['grouping_separator']);
     $numberFormat->setPlusSign($definition['plus_sign']);
     $numberFormat->setMinusSign($definition['minus_sign']);
     $numberFormat->setPercentSign($definition['percent_sign']);
     $numberFormat->setDecimalPattern($definition['decimal_pattern']);
     $numberFormat->setPercentPattern($definition['percent_pattern']);
     $numberFormat->setCurrencyPattern($definition['currency_pattern']);
     $numberFormat->setAccountingCurrencyPattern($definition['accounting_currency_pattern']);
     return $numberFormat;
 }
Пример #2
0
 /**
  * Helper for initiating a new NumberFormat object.
  */
 protected function createNumberFormat(array $definition, $locale = 'en')
 {
     $default = ['decimal_separator' => '.', 'grouping_separator' => ',', 'plus_sign' => '+', 'minus_sign' => '-', 'percent_sign' => '%'];
     $format = array_merge($default, $definition);
     $numberFormat = new NumberFormat();
     $numberFormat->setLocale($locale);
     $numberFormat->setNumberingSystem($format['numbering_system']);
     $numberFormat->setDecimalSeparator($format['decimal_separator']);
     $numberFormat->setGroupingSeparator($format['grouping_separator']);
     $numberFormat->setPlusSign($format['plus_sign']);
     $numberFormat->setMinusSign($format['minus_sign']);
     $numberFormat->setPercentSign($format['percent_sign']);
     $numberFormat->setDecimalPattern($format['decimal_pattern']);
     $numberFormat->setPercentPattern($format['percent_pattern']);
     $numberFormat->setCurrencyPattern($format['currency_pattern']);
     $numberFormat->setAccountingCurrencyPattern($format['accounting_currency_pattern']);
     return $numberFormat;
 }
Пример #3
0
 /**
  * @covers ::getDecimalPattern
  * @covers ::setDecimalPattern
  */
 public function testDecimalPattern()
 {
     $this->numberFormat->setDecimalPattern('#,##0.###');
     $this->assertEquals('#,##0.###', $this->numberFormat->getDecimalPattern());
 }