Skip to content

Commit

Permalink
Merge pull request #111 from putchi/patch-1
Browse files Browse the repository at this point in the history
Update Currency.php
  • Loading branch information
Torann authored Mar 9, 2020
2 parents 6154d6d + e7fdd5d commit 27b2b00
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(array $config, FactoryContract $cache)
* @param string $to
* @param bool $format
*
* @return string
* @return string|null
*/
public function convert($amount, $from = null, $to = null, $format = true)
{
Expand All @@ -86,12 +86,16 @@ public function convert($amount, $from = null, $to = null, $format = true)
return null;
}

// Convert amount
if ($from === $to) {
$value = $amount;
}
else {
$value = ($amount * $to_rate) / $from_rate;
try {
// Convert amount
if ($from === $to) {
$value = $amount;
} else {
$value = ($amount * $to_rate) / $from_rate;
}
} catch (\Exception $e) {
// Prevent invalid conversion or division by zero errors
return null;
}

// Should the result be formatted?
Expand Down

0 comments on commit 27b2b00

Please sign in to comment.