Swiftpack.co - paylike/swift-money as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by paylike.
paylike/swift-money 0.2.1
Money implementation in swift
⭐️ 0
🕓 1 year ago
.package(url: "https://github.com/paylike/swift-money.git", from: "0.2.1")

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: "[email protected]: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"

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics