Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tobiasschuerg/android-money
Simple money and currency converter library for android.
https://github.com/tobiasschuerg/android-money
android android-library currency currency-converter currency-exchange-rates hacktoberfest kotlin money
Last synced: 3 months ago
JSON representation
Simple money and currency converter library for android.
- Host: GitHub
- URL: https://github.com/tobiasschuerg/android-money
- Owner: tobiasschuerg
- License: mit
- Created: 2017-10-17T20:45:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-25T20:11:34.000Z (about 2 years ago)
- Last Synced: 2024-07-11T18:14:33.006Z (4 months ago)
- Topics: android, android-library, currency, currency-converter, currency-exchange-rates, hacktoberfest, kotlin, money
- Language: Kotlin
- Homepage:
- Size: 174 KB
- Stars: 67
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - tobiasschuerg/android-money - Simple money and currency converter library for android. (Kotlin)
README
[![Release](https://jitpack.io/v/tobiasschuerg/android-money.svg)](https://jitpack.io/#tobiasschuerg/android-money)
# android-money
Simple money and currency library for android (written in kotlin).
## Create Money
Creating money is as easy as:
```kotlin
// define your currencies
val euro = Currency("EUR", "Euro", 1.0)
val bitcoin = Currency("XBT", "Bitcoin", 0.000209580) // Oct. 17 2017, 21:00
// etc ...
val savedMoney = Money(1358.03, euro)
log("I saved $savedMoney")
```
> I saved 1.358,03 €## Convert Money
Also converting between currencies is straight forward:
```kotlin
val bitcoinMoney = savedMoney.convertInto(bitcoin)
log("I could invest my $availableMoney and get $bitcoinMoney instead")
```
> I could invest my 1.358,03 € and get 0,28020846 XBT instead## Money Calculations
### Simple Arithmetics
If using kotlin just use the default operators (+,-,*, /) or in java (`.plus()`, `.minus()`, ...):
```kotlin
val savedMoney = Money(1337, euro)
val birthdayMoney = Money(125, usDollar)
val availableMoney = savedMoney + birthdayMoney.convertInto(euro)
log("So in total I've now $availableMoney")
```
> So in total I've now 1.358,03 €### Summing up / Average
For summing up the `MoneyList`can be used:
```kotlin
val moneyList = MoneyList(usDollar)
moneyList.add(Money(100.01, usDollar))
moneyList.add(Money(1.27, usDollar))
moneyList.add(Money(20, usDollar))
moneyList.add(Money(13.37, usDollar))
log("In total I got: ${moneyList.sum()}")
```
> In total I got: $134.65# Add Library
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Step 2. Add the dependency
```
dependencies {
implementation 'com.github.tobiasschuerg:android-money:v0.3'
}
```