Skip to content

Commit

Permalink
Remove floating point operations
Browse files Browse the repository at this point in the history
  • Loading branch information
z38 committed Apr 27, 2018
1 parent 9fa3234 commit 33389d7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Z38/SwissPayment/Money/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public function format()
if ($this->getDecimals() > 0) {
$sign = ($this->cents < 0 ? '-' : '');
$base = pow(10, $this->getDecimals());
$minor = abs($this->cents) % $base;
$major = (abs($this->cents) - $minor) / $base;

return sprintf('%s%d.%0'.$this->getDecimals().'d', $sign, intval(abs($this->cents) / $base), abs($this->cents) % $base);
return sprintf('%s%d.%0'.$this->getDecimals().'d', $sign, $major, $minor);
} else {
return sprintf('%d', intval($this->cents));
return sprintf('%d', $this->cents);
}
}

Expand Down

0 comments on commit 33389d7

Please sign in to comment.