-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #7 Create a CurrencyProvider for decimal & rounding
- Loading branch information
Showing
10 changed files
with
187 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
fxcalc/src/main/java/net/objectlab/kit/fxcalc/CurrencyProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.objectlab.kit.fxcalc; | ||
|
||
public interface CurrencyProvider { | ||
int getFractionDigits(String currencyCode); | ||
|
||
int getRounding(String currencyCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
fxcalc/src/main/java/net/objectlab/kit/fxcalc/JdkCurrencyProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.objectlab.kit.fxcalc; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Currency; | ||
|
||
public class JdkCurrencyProvider implements CurrencyProvider { | ||
|
||
@Override | ||
public int getFractionDigits(String currencyCode) { | ||
try { | ||
return Currency.getInstance(currencyCode).getDefaultFractionDigits(); | ||
} catch (IllegalArgumentException iae) { | ||
// do nothing | ||
} | ||
return 2; | ||
} | ||
|
||
@Override | ||
public int getRounding(String currencyCode) { | ||
return "JPY".equalsIgnoreCase(currencyCode) ? BigDecimal.ROUND_DOWN : BigDecimal.ROUND_HALF_UP; | ||
} | ||
} |
Oops, something went wrong.