Small utility library to help working with payment amounts inside the Paylike ecosystem
Currently this package only supports a fraction of our JavaScript library. We may extend functionality later.
SPM:
// dependencies:
.package(url: "git@github.com:paylike/swift-money.git", .upToNextMajor(from: "0.2.1"))
// target:
.product(name: "PaylikeMoney", package: "swift-money")
Cocoapods: https://cocoapods.org/pods/PaylikeMoney
pod 'PaylikeMoney'
Use ISO 4217 currency codes
let eur = "EUR"
// Create from double
let amount = PaylikeMoney.fromDouble(currency: eur, n: 0.01) // EUR 0.01
// Create by hand
let amount2 = PaymentAmount(currency: eur, value: 1, exponent: 0) // EUR 1
amount.toString() // "EUR 0.01"
amount.toString(opts: PaymentAmountStringOptions(currency: false)) // "0.01"
amount.toString(opts: PaymentAmountStringOptions(padFractions: 3)) // "EUR 0.010"
amount.toString(opts: PaymentAmountStringOptions(padIntegers: 2)) // "EUR 0.01"