comp() public method

$this > $b : returns 1 , $this < $b : returns -1 , $this == $b : returns 0
public comp ( Decimal $b, integer $scale = null ) : integer
$b Decimal
$scale integer
return integer
Ejemplo n.º 1
0
 /**
  * Counts the number of significative digits of $val.
  * Assumes a consistent internal state (without zeros at the end or the start).
  *
  * @param  Decimal $val
  * @param  Decimal $abs $val->abs()
  * @return integer
  */
 private static function countSignificativeDigits(Decimal $val, Decimal $abs)
 {
     return strlen($val->value) - ($abs->comp(DecimalConstants::One()) === -1 ? 2 : max($val->scale, 1)) - ($val->isNegative() ? 1 : 0);
 }
Ejemplo n.º 2
0
 /**
  * Returns an integer less than, equal to, or greater than zero
  * if the value of this object is considered to be respectively
  * less than, equal to, or greater than the other
  *
  * @param Money $money
  * @return int
  */
 public function compare(Money $money)
 {
     $this->assertSameCurrency($money);
     return $this->amount->comp($money->amount, $this->getInnerPrecision());
 }