Example #1
0
 /**
  * toInteger.
  *
  * @param RoundingMode $roundingMode
  *
  * @return Integer
  */
 public function toInteger(RoundingMode $roundingMode = null)
 {
     if (null === $roundingMode) {
         $roundingMode = RoundingMode::HALF_UP();
     }
     $value = filter_var(round($this->value, 0, $roundingMode->getValue()), FILTER_VALIDATE_INT);
     return new Integer($value);
 }
Example #2
0
 public function testNegativeToNaturalHalfUp()
 {
     $real = new Real(-0.5);
     $natural = $real->toNatural(RoundingMode::HALF_UP());
     $this->assertInstanceOf(Natural::class, $natural);
     $this->assertSame(1, $natural->value());
 }