alexprengere / currencyconverter

A Python currency converter using the European Central Bank data.
http://alexprengere.github.io/currencyconverter
Apache License 2.0
215 stars 59 forks source link

Specifying default currency & string output #37

Closed kubinka0505 closed 2 years ago

kubinka0505 commented 2 years ago

I think that could be easily implemented with conditional statements

>>> import currency_converter as cc
>>>
>>> # Default currency specified
>>> c = cc.CurrencyConverter(default_currency = "GBP")
>>> 
>>> # 50 PLN to default currency with string output
>>> c.convert(50, "PLN", string = True)
'8.90 GBP'
>>> # 50 PLN to GBP without string output
>>> c.convert(50, "PLN", "GBP")
8.9
alexprengere commented 2 years ago

I think this can be easily implemented outside of the library, so there is no need to grow the API and add more attributes.

>>> import currency_converter as cc
>>> c = cc.CurrencyConverter()
>>> default_currency = "GBP"
>>>
>>> rate = c.convert(50, "PLN", default_currency)
>>> f"{rate:.2f} {default_currency}"
'9.33 GBP'

This way you can really format the output however you want.