CottaCush / CurrencyEditText

💰 A library to dynamically format your EditTexts to take currency inputs
Apache License 2.0
131 stars 28 forks source link

Basic information formatting number as currency #16

Closed webserveis closed 3 years ago

webserveis commented 3 years ago

It would be interesting if it was delimited correctly depending on how the android device is configured and also if you want to show another type of currency. I hope it helps

Extract info decimal formater

        val nf: NumberFormat = NumberFormat.getCurrencyInstance(Locale.getDefault())

        if (nf is DecimalFormat) {
            val sym: DecimalFormatSymbols = nf.decimalFormatSymbols

            Log.d(TAG, "currency: " + sym.currency)
            Log.d(TAG, "currencySymbol: " + sym.currencySymbol)
            Log.d(TAG, "decimalSeparator: " + sym.decimalSeparator)
            Log.d(TAG, "digit: " + sym.digit)
            Log.d(TAG, "exponentSeparator: " + sym.exponentSeparator)
            Log.d(TAG, "groupingSeparator: " + sym.groupingSeparator)
            Log.d(TAG, "infinity: " + sym.infinity)
            Log.d(TAG, "internationalCurrencySymbol: " + sym.internationalCurrencySymbol)
            Log.d(TAG, "minusSign: " + sym.minusSign)
            Log.d(TAG, "monetaryDecimalSeparator: " + sym.monetaryDecimalSeparator)
            Log.d(TAG, "naN: " + sym.naN)
            Log.d(TAG, "patternSeparator: " + sym.patternSeparator)
            Log.d(TAG, "perMill: " + sym.perMill)
            Log.d(TAG, "percent: " + sym.percent)
            Log.d(TAG, "zeroDigit: " + sym.zeroDigit)
        }

Set my devices in Spanish/Spain

Decimal Format detail

D/: currency: EUR
D/: currencySymbol: €
D/: decimalSeparator: ,
D/: digit: #
D/: exponentSeparator: E
D/: groupingSeparator: .
D/: infinity: ∞
D/: internationalCurrencySymbol: EUR
D/: minusSign: -
D/: monetaryDecimalSeparator: ,
D/: naN: NaN
D/: patternSeparator: ;
D/: perMill: ‰
D/: percent: %
D/: zeroDigit: 0

Print currency format

nf.format(2536) //2.536,00 €
nf.format(2536.3321F) //2.536,33 €
nf.format(999999999999999) //999.999.999.999.999,00 €
nf.format(0) //0,00 €
nf.format(-31) //-31,00 €
nf.format(-31.83F) //-31,83 €

Set my devices in Enghish/USA

Decimal Format detail

D/FirstFragment: currency: USD
D/FirstFragment: currencySymbol: $
D/FirstFragment: decimalSeparator: .
D/FirstFragment: digit: #
D/FirstFragment: exponentSeparator: E
D/FirstFragment: groupingSeparator: ,
D/FirstFragment: infinity: ∞
D/FirstFragment: internationalCurrencySymbol: USD
D/FirstFragment: minusSign: -
D/FirstFragment: monetaryDecimalSeparator: .
D/FirstFragment: naN: NaN
D/FirstFragment: patternSeparator: ;
D/FirstFragment: perMill: ‰
D/FirstFragment: percent: %
D/FirstFragment: zeroDigit: 0

Print currency format

nf.format(2536) //$2,536.00
nf.format(2536.3321F) //$2,536.33
nf.format(999999999999999) //$999,999,999,999,999.00
nf.format(0) //$0.00
nf.format(-31) //-$31.00
nf.format(-31.83F) //-$31.83

Devices in English/USA

represent a currency different from that established by the system

 nf.currency = Currency.getInstance("EUR")

result view that the euro symbol is displayed at the beginning, as is the system set by the user

nf.format(2536) //€2,536.00
nf.format(2536.3321F) //€2,536.33
nf.format(999999999999999) //€999,999,999,999,999.00
nf.format(0) //€0.00
nf.format(-31) //-€31.00
nf.format(-31.83F) //-€31.83

Extra

Get available currencies

listCurrencies = Currency.getAvailableCurrencies()
    .filter { !it.displayName.contains("(") }
    .sortedBy { it.currencyCode }
    .map { it.displayName }
rasheedsulayman commented 3 years ago

@efguydan Do you want to check this?

efguydan commented 3 years ago

Hello @webserveis, Thanks for the detailed comment. I am not sure I fully understand it though. The library currently allows you to configure a specific locale for it to use. It uses the device's locale if no locale was specified. It also allows you to configure a currency symbol to use.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.