A simple, pure Kotlin library for formatting numbers as currency strings with flexible options.
- Locale-aware currency formatting
- Custom currency code support (ISO 4217)
- Configurable minimum and maximum fraction digits
- Option to show or hide the currency symbol
- Thread-safe formatting
- Utility to list all supported currency codes
Add JitPack to your root build.gradle.kts (or build.gradle):
allprojects {
repositories {
maven { url = uri('https://jitpack.io') } // add this line
}
}Then add the dependency to your module build.gradle:
dependencies {
implementation 'com.github.jksalcedo:currency-formatter-kt:1.0.0'
}Add the CurrencyFormatter class to your project.
import java.util.Locale
fun main() {
val formatter = CurrencyFormatter(
locale = Locale.US,
currencyCode = "PHP",
minFractionDigits = 2,
maxFractionDigits = 2,
showSymbol = true
)
println(formatter.format(1234.45)) // ₱1,234.45
println(CurrencyFormatter.availableCurrencyCodes()) // List of all codes
}| Parameter | Type | Description |
|---|---|---|
locale |
Locale | Locale for formatting (default: system) |
currencyCode |
String | ISO 4217 currency code (default: from locale) |
minFractionDigits |
Int? | Minimum fraction digits (optional) |
maxFractionDigits |
Int? | Maximum fraction digits (optional) |
showSymbol |
Boolean | Show currency symbol (default: true) |
format(amount: Number): String— Formats the given amount.CurrencyFormatter.availableCurrencyCodes(): List<String>— Returns all supported currency codes.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Make your changes and add tests if needed.
- Open a pull request with a clear description of your changes.
Please follow the existing code style and conventions.