asDecimal() 공개 메소드

Property [[decimalSeparator]] will be used to represent the decimal point. The value is rounded automatically to the defined decimal digits.
또한 보기: decimalSeparator
또한 보기: thousandSeparator
public asDecimal ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$decimals integer the number of digits after the decimal point. If not given the number of digits is determined from the [[locale]] and if the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available defaults to `2`.
$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]].
리턴 string the formatted result.
예제 #1
0
 public function testAsDecimal()
 {
     $value = '123';
     $this->assertSame($value, $this->formatter->asDecimal($value));
     $value = '123456';
     $this->assertSame("123,456", $this->formatter->asDecimal($value));
     $value = '-123456.123';
     $this->assertSame("-123,456.123", $this->formatter->asDecimal($value));
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDecimal(null));
 }
예제 #2
0
 public function testAsDecimal()
 {
     $value = 123.12;
     $this->assertSame("123.12", $this->formatter->asDecimal($value));
     $this->assertSame("123.1", $this->formatter->asDecimal($value, 1));
     $this->assertSame("123", $this->formatter->asDecimal($value, 0));
     $value = 123;
     $this->assertSame("123.00", $this->formatter->asDecimal($value));
     $this->formatter->decimalSeparator = ',';
     $this->formatter->thousandSeparator = '.';
     $value = 123.12;
     $this->assertSame("123,12", $this->formatter->asDecimal($value));
     $this->assertSame("123,1", $this->formatter->asDecimal($value, 1));
     $this->assertSame("123", $this->formatter->asDecimal($value, 0));
     $value = 123123.123;
     $this->assertSame("123.123,12", $this->formatter->asDecimal($value));
     $value = 123123.123;
     $this->assertSame("123.123,12", $this->formatter->asDecimal($value));
     $this->assertSame("123.123,12", $this->formatter->asDecimal($value, 2));
     $this->formatter->decimalSeparator = ',';
     $this->formatter->thousandSeparator = ' ';
     $this->assertSame("123 123,12", $this->formatter->asDecimal($value));
     $this->assertSame("123 123,12", $this->formatter->asDecimal($value, 2));
     $this->formatter->thousandSeparator = '';
     $this->assertSame("123123,12", $this->formatter->asDecimal($value));
     $this->assertSame("123123,12", $this->formatter->asDecimal($value, 2));
     $this->formatter->decimalSeparator = null;
     $this->formatter->thousandSeparator = null;
     $value = '-123456.123';
     $this->assertSame("-123,456.123", $this->formatter->asDecimal($value, 3));
     // null display
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDecimal(null));
 }
예제 #3
0
 public function testAsDecimal()
 {
     $value = '123';
     $this->assertSame($value, $this->formatter->asDecimal($value));
     $value = '123456';
     $this->assertSame("123,456", $this->formatter->asDecimal($value));
     $value = '-123456.123';
     if (defined('HHVM_VERSION')) {
         // the default format is different on HHVM
         $this->assertSame("-123,456", $this->formatter->asDecimal($value));
     } else {
         $this->assertSame("-123,456.123", $this->formatter->asDecimal($value));
     }
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDecimal(null));
 }