/**
  * 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;
 }
 /**
  * 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;
 }
Example #3
0
 /**
  * @covers ::getGroupingSeparator
  * @covers ::setGroupingSeparator
  */
 public function testGroupingSeparator()
 {
     $this->numberFormat->setGroupingSeparator(',');
     $this->assertEquals(',', $this->numberFormat->getGroupingSeparator());
 }