Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function format($value, array $options = [])
 {
     if (!is_numeric($value)) {
         throw new InvalidTypeException(sprintf('The number formatter expects a numeric value, got "%s".', is_object($value) ? get_class($value) : gettype($value)));
     }
     $scale = isset($options['scale']) ? $options['scale'] : 2;
     $rounding = isset($options['rounding']) ? $options['rounding'] : \NumberFormatter::ROUND_HALFUP;
     $grouping = isset($options['grouping']) ? $options['grouping'] : false;
     $formatter = new \NumberFormatter($this->localeContext->getLocale(), \NumberFormatter::DECIMAL);
     $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $scale);
     $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $rounding);
     $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $grouping);
     return str_replace(" ", ' ', $formatter->format($value));
 }
 /**
  * @expectedException \Lug\Component\Grid\Exception\InvalidTypeException
  * @expectedExceptionMessage The number formatter expects a numeric value, got "string".
  */
 public function testFormatWithoutNumber()
 {
     $this->formatter->format('foo', []);
 }