taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

commit ddf18ca8b1fa64bc439b5fa39a78b751f7ba5281
parent c7834ba68ef909825caf9a321dc4aec6849a208f
Author: Iván Ávalos <avalos@disroot.org>
Date:   Wed, 24 Jul 2024 09:04:19 -0600

[wallet] Do not round amounts any longer

Diffstat:
Mtaler-kotlin-android/src/main/java/net/taler/common/Amount.kt | 2+-
Mtaler-kotlin-android/src/test/java/net/taler/common/AmountTest.kt | 32++++++++++++++++++++------------
2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/taler-kotlin-android/src/main/java/net/taler/common/Amount.kt b/taler-kotlin-android/src/main/java/net/taler/common/Amount.kt @@ -239,8 +239,8 @@ data class Amount( // There is currency spec, so we can do things right val format = NumberFormat.getCurrencyInstance() - format.maximumFractionDigits = spec.numFractionalNormalDigits format.minimumFractionDigits = spec.numFractionalTrailingZeroDigits + format.maximumFractionDigits = MAX_FRACTION_LENGTH s.currencySymbol = spec.symbol ?: "" (format as DecimalFormat).decimalFormatSymbols = s diff --git a/taler-kotlin-android/src/test/java/net/taler/common/AmountTest.kt b/taler-kotlin-android/src/test/java/net/taler/common/AmountTest.kt @@ -26,15 +26,6 @@ import kotlin.random.Random class AmountTest { - companion object { - fun getRandomAmount() = getRandomAmount(getRandomString(1, Random.nextInt(1, 12))) - fun getRandomAmount(currency: String): Amount { - val value = Random.nextLong(0, Amount.MAX_VALUE) - val fraction = Random.nextInt(0, Amount.MAX_FRACTION) - return Amount(currency, value, fraction) - } - } - @Test fun testFromJSONString() { var str = "TESTKUDOS:23.42" @@ -89,13 +80,30 @@ class AmountTest { ), rawStr = "23.42", fraction = 42000000, - specAmount = "23", + specAmount = "23.42", noSpecAmount = "23.42", currency = "TESTKUDOS", symbol = "テ", ) amountToString( + amount = Amount.fromString("TESTKUDOS", "23"), + spec = CurrencySpecification( + name = "Test (Taler Unstable Demostrator)", + numFractionalInputDigits = 0, + numFractionalNormalDigits = 0, + numFractionalTrailingZeroDigits = 0, + altUnitNames = mapOf(0 to "テ"), + ), + rawStr = "23", + fraction = 0, + specAmount = "23", + noSpecAmount = "23", + currency = "TESTKUDOS", + symbol = "テ", + ) + + amountToString( amount = Amount.fromString("BITCOINBTC", "0.00000001"), spec = CurrencySpecification( name = "Bitcoin", @@ -134,7 +142,7 @@ class AmountTest { spec = specEUR, rawStr = "1500000000.00000003", fraction = 3, - specAmount = "1,500,000,000.00", + specAmount = "1,500,000,000.00000003", noSpecAmount = "1,500,000,000.00000003", currency = "EUR", symbol = "€", @@ -145,7 +153,7 @@ class AmountTest { spec = specEUR, rawStr = "500000000.126", fraction = 12600000, - specAmount = "500,000,000.13", + specAmount = "500,000,000.126", noSpecAmount = "500,000,000.126", currency = "EUR", symbol = "€",