Skip to content

Commit

Permalink
Add is_zero() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Mar 21, 2023
1 parent ae4b9d1 commit 0ebce4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,15 @@ public function negative() {
$this->currency
);
}

/**
* Checks if the value represented by this object is zero.
*
* @link https://github.com/moneyphp/money/blob/v4.0.1/src/Money.php#L425-L431
* @link https://github.com/pronamic/wp-money/issues/7
* @return bool True if zero, false otherwise.
*/
public function is_zero() {
return $this->amount->is_zero();
}
}
17 changes: 17 additions & 0 deletions tests/src/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,21 @@ public function test_negative() {
$this->assertSame( '-149.25', $money->number_format( null, '.', '' ) );
$this->assertSame( '149.25', $negative->number_format( null, '.', '' ) );
}

/**
* Test is zero.
*/
public function test_is_zero() {
$money = new Money( '0', 'EUR' );

$this->assertTrue( $money->is_zero() );

$money = new Money( '-0', 'EUR' );

$this->assertTrue( $money->is_zero() );

$money = new Money( '10', 'EUR' );

$this->assertFalse( $money->is_zero() );
}
}

0 comments on commit 0ebce4a

Please sign in to comment.