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:
parent
1746be6e10
commit
9c72c86ed1
@ -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
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user