Fix boosts made in UGX.
This commit is contained in:
parent
061b87ead0
commit
22e79a045c
2 changed files with 27 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue