ash-jc-allen / laravel-exchange-rates

A Laravel wrapper package for interacting with the exchangeratesapi.io API.
MIT License
449 stars 49 forks source link

convert() method does not calculate accurately #49

Closed dobstera closed 4 years ago

dobstera commented 4 years ago

When you try to convert a float value (say 42.65), the calculation is not correct, because the input $value is cast to int instead of float in "ExchangeRate" class at line 242:

public function convert(int $value, string $from, $to, Carbon $date = null)

ash-jc-allen commented 4 years ago

Hi @dobstera, sorry to hear that you're having problems.

The convert() method accepts integers for monetary value. You'll need to pass it in in your currencies lowest denomination. For example, to convert $0.99 you'd need to pass in 99 and to convert $2.99 you'd need to pass in 299.

There's an example in the docs if this helps: https://github.com/ash-jc-allen/laravel-exchange-rates#convert-currencies

I hope you manage to get it working 😃