Skip to content

jksalcedo/currency-formatter-kt

Repository files navigation

CurrencyFormatter

A simple, pure Kotlin library for formatting numbers as currency strings with flexible options.

Features

  • 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

Installation

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'
}

Usage

Add the CurrencyFormatter class to your project.

Example

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
}

API

CurrencyFormatter Constructor

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)

Methods

  • format(amount: Number): String — Formats the given amount.
  • CurrencyFormatter.availableCurrencyCodes(): List<String> — Returns all supported currency codes.

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Make your changes and add tests if needed.
  4. Open a pull request with a clear description of your changes.

Please follow the existing code style and conventions.

About

A simple, pure Kotlin library for formatting numbers as currency strings with flexible options.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages