Matthew Layton
Matthew Layton

Reputation: 42260

Kotlin/Java - Default Fraction Digits of the Currency Class

Consider the following Kotlin code sample:

import java.util.*

fun main(vararg args: String) {
    Currency
        .getAvailableCurrencies()
        .sortedBy { it.currencyCode }
        .forEach {
            val cc = it.currencyCode
            val fd = it.defaultFractionDigits
            println("$cc = $fd")
        }
}

Example output:

ADP = 0

AED = 2

AFA = 2

...

XAG = -1

What I want to know specifically relating to currencies such as XAG (Troy Ounce of Silver), what is meant by having a -1 (negative 1) fractional digit?

Upvotes: 0

Views: 386

Answers (1)

maio290
maio290

Reputation: 6732

In the case of pseudo-currencies, such as IMF Special Drawing Rights, -1 is returned.

So it just means that XAG isn't a real currency.

Source: https://developer.android.com/reference/kotlin/java/util/Currency#getDefaultFractionDigits()

Upvotes: 3

Related Questions