3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-20 22:25:50 +00:00

Monetary: Tiny optimization in parseCoin()/parseFiat().

This commit is contained in:
Andreas Schildbach 2016-10-22 19:14:09 +02:00
parent 1746be6e10
commit 9c72c86ed1
2 changed files with 2 additions and 3 deletions

View File

@ -125,7 +125,7 @@ public final class Coin implements Monetary, Comparable<Coin>, Serializable {
*/ */
public static Coin parseCoin(final String str) { public static Coin parseCoin(final String str) {
try { try {
long satoshis = new BigDecimal(str).movePointRight(SMALLEST_UNIT_EXPONENT).toBigIntegerExact().longValue(); long satoshis = new BigDecimal(str).movePointRight(SMALLEST_UNIT_EXPONENT).longValueExact();
return Coin.valueOf(satoshis); return Coin.valueOf(satoshis);
} catch (ArithmeticException e) { } catch (ArithmeticException e) {
throw new IllegalArgumentException(e); // Repackage exception to honor method contract throw new IllegalArgumentException(e); // Repackage exception to honor method contract

View File

@ -84,8 +84,7 @@ public final class Fiat implements Monetary, Comparable<Fiat>, Serializable {
*/ */
public static Fiat parseFiat(final String currencyCode, final String str) { public static Fiat parseFiat(final String currencyCode, final String str) {
try { try {
long val = new BigDecimal(str).movePointRight(SMALLEST_UNIT_EXPONENT) long val = new BigDecimal(str).movePointRight(SMALLEST_UNIT_EXPONENT).longValueExact();
.toBigIntegerExact().longValue();
return Fiat.valueOf(currencyCode, val); return Fiat.valueOf(currencyCode, val);
} catch (ArithmeticException e) { } catch (ArithmeticException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);