예제 #1
0
 /**
  * Round a number to the nearest int, ( 1.2 > 1 && 1.8 > 2)
  * @param size_t precision the rounding prescision
  * @return BigNumber this number rounded to 'x' precision.
  */
 public function Round($precision = 0)
 {
     // if it is not a number than there is no rounding to do.
     if ($this->IsNan()) {
         return $this;
     }
     if ($this->IsNeg()) {
         $this->_neg = false;
         $this->Round($precision);
         $this->_neg = true;
         // already cleaned up.
         return $this;
     }
     // add 0.5 and floor(...) it.
     $number = new BigNumber(5);
     $number->DivideByBase($precision + 1);
     $x = static::AbsAdd($number, $this);
     $this->_Copy($x->Floor($precision));
     // clean up.
     return $this->PerformPostOperations($precision);
 }