moderateepheezy / SinzuMoney

This is a simple type safe Money library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SinzuMoney

This is a simple type-safe representation of a Monetary.

Swift Version License Platform CocoaPods Compatible

Requirements

  • iOS 12.0+
  • Xcode 11

Installation

CocoaPods

You can use CocoaPods to install YourLibrary by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'SinzuMoney'

Usage example

import SinzuMoney

Sinzu Money uses Naira as its default currency type and can be initialized with any money value:

let money = Money.from(value: 10.32) // Positive value

let localizeMoney = money.localized
print(localizeMoney) //returns  ₦10.32

let localizedMoney = Money.from(value: -10000000.32) // Negative value
let localized = localizedMoney.localized

print(localizedMoney) // returns ₦-10,000,000.32


But it isn’t restricted to just Naira you can use any currency type known on earth by simply using the currency code:


let usDollarCurrency = Money.Currency(code: "USD", name: "Dollar", symbol: "$", baseUnit: "US Dollar", decimalUnit: "Cent”). 

let moneyWithNewCurrency = money.newWith(currency: usDollarCurrency)

print(moneyWithNewCurrency.localizedBalance) // returns $1,234.23K


You can also change only the currency symbol:

let dollarCurrency = Money.Currency.from(code: "$")

let newDollarCurrencyMoney = money.newWith(currency: dollarCurrency)

print(newDollarCurrencyMoney.localizedBalance) // returns  $1,234.23K

Sinzu Money can help you get the monetary unit of any value:

 let thousandMoney = Money.from(value: 30000.00)

 print(thousandMoney.unit) // returns “K”

 let millionMoney = Money.from(value: 3000000.00)
 
print(millionMoney.unit) //  returns M

 let billionMoney = Money.from(value: 30000000000.00)

 print(billionMoney.unit) // returns B

Sinzu Money can also help you get human readable value:

let localizedMoney = Money.from(value: 1240000.6254204)
let localized = localizedMoney.humanReadable
print(localizedMoney) // returns 1,240,000.63

You can also get a suffix value of any amount:

 let thousandMoney = Money.from(value: 30000.00)

 print(thousandMoney.suffixAmount) // returns  +30K

 let millionMoney = Money.from(value: 3000000.00)
  
 print(millionMoney.suffixAmount) // returns  +3M 

 let billionMoney = Money.from(value: -30000000000.00)

 print(billionMoney.suffixAmount) // returns  -30B

If you want to send monetary value to backend, you can covert your value to either decimal or integer:

let money = Money.from(value: 1234.23)

print(money.backendDecimalPostableAmount) // returns 123423
print(money.backendIntegerPostableAmount) // returns  123400

Contribute

We would love you for the contribution to SinzuMoney, check the LICENSE file for more info.

About

This is a simple type safe Money library

License:MIT License


Languages

Language:Swift 95.1%Language:Ruby 2.9%Language:Objective-C 2.0%