本文整理汇总了PHP中Math::sub方法的典型用法代码示例。如果您正苦于以下问题:PHP Math::sub方法的具体用法?PHP Math::sub怎么用?PHP Math::sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Math
的用法示例。
在下文中一共展示了Math::sub方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSub
public function testSub()
{
$math = new Math();
//Success
$this->assertEquals(3, $math->sub(8, 5));
//Success
$this->assertEquals(3, $math->sub(9, 6));
}
示例2: minus
/**
* Returns the difference of this number and the given one.
*
* The result has a scale of `max($this->scale, $that->scale)`.
*
* @param \Arki\Math\Number|int|float|string $that The number to subtract. Must be convertible to a BigDecimal.
*
* @return BigDecimal The result.
*
* @throws \ArithmeticError If the number is not valid, or is not convertible to a BigDecimal.
*/
public function minus($that)
{
$that = self::of($that);
if ($that->intVal->isZero() && $that->scale <= $this->scale) {
return $this;
}
$this->scaleValues($this, $that, $a, $b);
$value = Math::sub($a, $b);
$scale = $this->scale > $that->scale ? $this->scale : $that->scale;
return new self(BigInteger::of($value), $scale);
}