Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Bad responce format in ExchangeRates().toFiat #47

Open
POSTAL5532 opened this issue Apr 18, 2018 · 1 comment
Open

Bad responce format in ExchangeRates().toFiat #47

POSTAL5532 opened this issue Apr 18, 2018 · 1 comment

Comments

@POSTAL5532
Copy link

Hey. Today I sat down to study your api. So there was a small problem in the example line:
BigDecimal BTCToUSD = exchange.toFiat("USD", new BigDecimal(100000000)); - throw

java.lang.NumberFormatException
at java.math.BigDecimal.(BigDecimal.java:494)
at java.math.BigDecimal.(BigDecimal.java:383)
at java.math.BigDecimal.(BigDecimal.java:806)
at info.blockchain.api.exchangerates.ExchangeRates.toFiat(ExchangeRates.java:96)

I ran the code in debug mode and found that in the line
return new BigDecimal(response);
in ExchangeRates().toFiat() in response, the value is returned in the following form: 819,060,000,000. I'm not a very experienced developer, but it seems to me that BigDecimal can not process commas in this sense. I will be glad to any answer. Thank you and sorry for my english)

@POSTAL5532
Copy link
Author

POSTAL5532 commented Apr 18, 2018

public class CustomExchangeRates extends ExchangeRates {

@Override
public BigDecimal toFiat(String currency, BigDecimal value) throws APIException, IOException {
    Map<String, String> params = new HashMap();
    params.put("currency", currency);
    params.put("value", String.valueOf(value.multiply(BigDecimal.valueOf(100000000L))));
    String response = HttpClient.getInstance().get("frombtc", params);
    response = response.replaceAll(",", "");
    return new BigDecimal(response);
}

}

It's work for me!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant