mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-27 21:24:42 +00:00
Fix boosts made in UGX.
This commit is contained in:
committed by
Greyson Parrelli
parent
061b87ead0
commit
22e79a045c
@@ -54,14 +54,16 @@ public class FiatMoney {
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This special cases UGX to act as two decimal.
|
||||
*
|
||||
* @return amount, in smallest possible units (cents, yen, etc.)
|
||||
*/
|
||||
public @NonNull String getMinimumUnitPrecisionString() {
|
||||
NumberFormat formatter = NumberFormat.getInstance();
|
||||
formatter.setMaximumFractionDigits(0);
|
||||
formatter.setGroupingUsed(false);
|
||||
BigDecimal multiplicand = BigDecimal.TEN.pow(currency.getDefaultFractionDigits());
|
||||
|
||||
|
||||
BigDecimal multiplicand = BigDecimal.TEN.pow(currency.getCurrencyCode().equals("UGX") ? 2 : currency.getDefaultFractionDigits());
|
||||
|
||||
return formatter.format(amount.multiply(multiplicand));
|
||||
}
|
||||
|
||||
@@ -57,4 +57,27 @@ public class FiatMoneyTest {
|
||||
assertEquals("100", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void given100UGX_whenIGetDefaultPrecisionString_thenIExpect100() {
|
||||
// GIVEN
|
||||
FiatMoney fiatMoney = new FiatMoney(BigDecimal.valueOf(100), Currency.getInstance("UGX"));
|
||||
|
||||
// WHEN
|
||||
String result = fiatMoney.getDefaultPrecisionString();
|
||||
|
||||
// THEN
|
||||
assertEquals("100", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void given100UGX_whenIGetMinimumUnitPrecisionString_thenIExpect10000() {
|
||||
// GIVEN
|
||||
FiatMoney fiatMoney = new FiatMoney(BigDecimal.valueOf(100), Currency.getInstance("UGX"));
|
||||
|
||||
// WHEN
|
||||
String result = fiatMoney.getMinimumUnitPrecisionString();
|
||||
|
||||
// THEN
|
||||
assertEquals("10000", result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user