asPercent() public method

Formats the value as a percent number with "%" sign.
public asPercent ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted. It must be a factor e.g. `0.75` will result in `75%`.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
return string the formatted result.
Ejemplo n.º 1
0
 public function testAsPercent()
 {
     $value = '123';
     $this->assertSame('12,300%', $this->formatter->asPercent($value));
     $value = '0.1234';
     $this->assertSame("12%", $this->formatter->asPercent($value));
     $value = '-0.009343';
     $this->assertSame("-1%", $this->formatter->asPercent($value));
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asPercent(null));
 }
Ejemplo n.º 2
0
 public function testAsPercent()
 {
     if (defined('HHVM_VERSION')) {
         // the default format is different on HHVM
         $this->markTestSkipped('HHVM behaves quite different in the default patterns used for formatting.');
     }
     $value = '123';
     $this->assertSame('12,300%', $this->formatter->asPercent($value));
     $value = '0.1234';
     $this->assertSame("12%", $this->formatter->asPercent($value));
     $value = '-0.009343';
     $this->assertSame("-1%", $this->formatter->asPercent($value));
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asPercent(null));
 }
Ejemplo n.º 3
0
 public function testAsPercent()
 {
     $this->assertSame('12,300%', $this->formatter->asPercent(123));
     $this->assertSame('12,300%', $this->formatter->asPercent('123'));
     $this->assertSame("12%", $this->formatter->asPercent(0.1234));
     $this->assertSame("12%", $this->formatter->asPercent('0.1234'));
     $this->assertSame("-1%", $this->formatter->asPercent(-0.009343000000000001));
     $this->assertSame("-1%", $this->formatter->asPercent('-0.009343'));
     // null display
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asPercent(null));
 }