Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert a currency given an exchange rate #54

Open
adrianmarino opened this issue Nov 30, 2016 · 4 comments
Open

Convert a currency given an exchange rate #54

adrianmarino opened this issue Nov 30, 2016 · 4 comments

Comments

@adrianmarino
Copy link

For example:

# Knowing that 1 USD is equivalent to 15 ARS...
usd = Money.new(100, :USD)
ars = Money.exchange from: usd, to: :ARS, rate: 15
assert ars == Money.new(1500, :ARS)

or

Money.rate(:USD, :ARS, 15)
usd = Money.new(100, :USD)
ars = Money.convert usd, to: :ARS
assert ars == Money.new(1500, :ARS)
@adrianmarino adrianmarino changed the title Allow currency convertion given an exchange rate Convert a currency given an exchange rate Nov 30, 2016
@maennchen
Copy link

Have a look at this library: (I built exactly for that use case)
https://github.com/jshmrtn/currency-conversion

@Nitrino
Copy link
Member

Nitrino commented Feb 17, 2019

This feature includes a list for implementation in the near future.

@theguuholi
Copy link

I am going to try to implement this feature.

@lessless
Copy link

lessless commented Oct 30, 2022

This will be nice to have indeed. My 5c for using rate and keeping it stateless:

usd = Money.new(100, :USD)
ars = Money.convert(usd, to: :ARS, rate: 15)
assert ars == Money.new(1500, :ARS)

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

No branches or pull requests

5 participants