Skip to content

paylike/swift-money

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

PaylikeMoney

Small utility library to help working with payment amounts inside the Paylike ecosystem

Features

Currently this package only supports a fraction of our JavaScript library. We may extend functionality later.

Install

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'

Usage

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"

About

Money implementation in swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published