Skip to content

Commit

Permalink
fix: make Mollie::Amount compatible with older versions of crystal
Browse files Browse the repository at this point in the history
  • Loading branch information
wout committed Jul 31, 2021
1 parent 4eaff1a commit 7b318b9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion shard.yml
@@ -1,5 +1,5 @@
name: mollie
version: 1.3.0
version: 1.3.2

authors:
- wout <hi@wout.codes>
Expand Down
2 changes: 1 addition & 1 deletion src/mollie/amount.cr
Expand Up @@ -15,7 +15,7 @@ struct Mollie

def to_tuple
{
value: Util.amount_with_decimals(@value.to_f64, @currency),
value: Util.amount_with_decimals(@value, @currency),
currency: @currency,
}
end
Expand Down
5 changes: 2 additions & 3 deletions src/mollie/util.cr
Expand Up @@ -57,10 +57,9 @@ struct Mollie
currency : String
)
decimals = Mollie::Config.currency_decimals[currency]? || 2
rounded = amount.to_f.round(decimals, mode: Number::RoundingMode::TIES_AWAY)

return amount.round.to_i.to_s if decimals.zero?

"%.#{decimals}f" % amount.round(decimals, mode: Number::RoundingMode::TIES_AWAY)
decimals.zero? ? rounded.to_i.to_s : "%.#{decimals}f" % rounded
end

private def self.escape(value : String | Symbol)
Expand Down
2 changes: 1 addition & 1 deletion src/mollie/version.cr
@@ -1,3 +1,3 @@
struct Mollie
VERSION = "v1.3.1"
VERSION = "v1.3.2"
end

0 comments on commit 7b318b9

Please sign in to comment.