asInteger() public method

Formats the value as an integer number by removing any decimal digits without rounding.
public asInteger ( mixed $value, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$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.
コード例 #1
0
 public function testAsScientific()
 {
     $value = '123';
     $this->assertSame('1.23E+2', $this->formatter->asScientific($value, 2));
     $value = '123456';
     $this->assertSame("1.234560E+5", $this->formatter->asScientific($value));
     $value = '-123456.123';
     $this->assertSame("-1.234561E+5", $this->formatter->asScientific($value));
     // empty input
     $this->assertSame("0", $this->formatter->asInteger(false));
     $this->assertSame("0", $this->formatter->asInteger(""));
     // null display
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asScientific(null));
 }
コード例 #2
0
ファイル: FormatterNumberTest.php プロジェクト: howq/yii2
 /**
  * @expectedException \yii\base\InvalidParamException
  */
 public function testAsIntegerException2()
 {
     $this->formatter->asInteger('-123abc');
 }
コード例 #3
0
ファイル: FormatterTest.php プロジェクト: aivavic/yii2
 /**
  * @expectedException \yii\base\InvalidParamException
  */
 public function testAsIntegerException4()
 {
     $this->formatter->asInteger(false);
 }
コード例 #4
0
ファイル: FormatterTest.php プロジェクト: albertborsos/yii2
 /**
  * @expectedException \yii\base\InvalidParamException
  */
 public function testAsIntegerException2()
 {
     $this->assertSame("0", $this->formatter->asInteger('-123abc'));
 }