项目作者: fluidsonic

项目描述 :
Kotlin multiplatform currency library (alpha)
高级语言: Kotlin
项目地址: git://github.com/fluidsonic/fluid-currency.git
创建时间: 2020-08-22T16:14:05Z
项目社区:https://github.com/fluidsonic/fluid-currency

开源协议:Apache License 2.0

下载


fluid-currency

Maven Central
Tests
Kotlin-blue.svg)
#fluid-libraries Slack Channel

Kotlin multiplatform currency library.

This is most useful in combination with fluid-i18n for retrieving internationalized information about a currency.

Installation

build.gradle.kts:

  1. dependencies {
  2. implementation("io.fluidsonic.currency:fluid-currency:0.13.0")
  3. }

Usage

  1. println(Currency.fromCode("EUR")) // EUR

class Currency

A class with information about a specific currency defined by ISO 4217.

  1. val currency = Currency.forCode("EUR") // throws if code is invalid (not defined by ISO 4217) or has an invalid format (not three latin letters)
  2. println(currency.code) // EUR
  3. println(currency.defaultFractionDigits) // 2
  4. println(currency.numericCode) // 978
  1. val currency = Currency.forCodeOrNull("ABC123") // null if code is invalid (not defined by ISO 4217) or has an invalid format (not three latin letters)
  2. println(currency) // null

class CurrencyCode

An inline class for ISO 4217 3-letter currency codes (e.g. EUR or USD).

  1. val code = CurrencyCode.parse("EUR") // throws if code has invalid format (not three latin letters)
  2. println(code.toString()) // EUR
  3. println(code.isValid()) // true - 'EUR' is defined by ISO 4217
  1. val code = CurrencyCode.parse("abc") // throws if code has invalid format (not three latin letters)
  2. println(code.toString()) // ABC
  3. println(code.isValid()) // false - 'ABC' is not defined by ISO 4217
  1. val code = CurrencyCode.parseOrNull("ABC123") // null if code has invalid format (not three latin letters)
  2. println(code) // null

License

Apache 2.0