exchangerate.host icon indicating copy to clipboard operation
exchangerate.host copied to clipboard

Convert Endpoint: Places not returning expected behaviour

Open indygill opened this issue 2 years ago • 0 comments

According to the docs, the "places" parameter will return a result rounded to x decimal places.

places [optional] Round numbers to decimal place. example:places=2

However if I request the following:

https://api.exchangerate.host/convert?from=BTC&to=USD&amount=1&date=2022-06-04&places=2

It returns the following. As you can see the result is null.

// 20220604150525
// https://api.exchangerate.host/convert?from=BTC&to=USD&amount=1&date=2022-06-04&places=2

{
  "motd": {
    "msg": "If you or your company use this project or like what we doing, please consider backing us so we can continue maintaining and evolving this project.",
    "url": "https://exchangerate.host/#/donate"
  },
  "success": true,
  "query": {
    "from": "BTC",
    "to": "USD",
    "amount": 1
  },
  "info": {
    "rate": null
  },
  "historical": true,
  "date": "2022-06-04",
  "result": null
}

If I call the following instead (&places=5):

https://api.exchangerate.host/convert?from=BTC&to=USD&amount=1&date=2022-06-04&places=5

It then returns the expected behaviour, but it seems the "places" parameter returns x digits before the decimal, when it should be after?

// 20220604150811
// https://api.exchangerate.host/convert?from=BTC&to=USD&amount=1&date=2022-06-04&places=5

{
  "motd": {
    "msg": "If you or your company use this project or like what we doing, please consider backing us so we can continue maintaining and evolving this project.",
    "url": "https://exchangerate.host/#/donate"
  },
  "success": true,
  "query": {
    "from": "BTC",
    "to": "USD",
    "amount": 1
  },
  "info": {
    "rate": 26810.75
  },
  "historical": true,
  "date": "2022-06-04",
  "result": 26810.75
}

indygill avatar Jun 04 '22 14:06 indygill