Skip to content

Commit

Permalink
currency: keep amount around in string form for output
Browse files Browse the repository at this point in the history
Kind of annoying to get things like "1e06 XLM" in the output when we've
been so careful to make sure the converted value won't be printed as
engineering notation. This is a simple fix.
  • Loading branch information
dgw committed May 10, 2021
1 parent 2f693f3 commit 181f9da
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sopel/modules/currency.py
Expand Up @@ -141,15 +141,15 @@ def exchange(bot, match):
query = match.string

targets = query.split()
amount = targets.pop(0)
amount_in = targets.pop(0)
base = targets.pop(0)
targets.pop(0)

# TODO: Use this instead after dropping Python 2 support
# amount, base, _, *targets = query.split()

try:
amount = float(amount)
amount = float(amount_in)
except ValueError:
bot.reply(UNRECOGNIZED_INPUT)
return
Expand All @@ -161,7 +161,7 @@ def exchange(bot, match):
bot.reply("Zero is zero, no matter what country you're in.")
return

out_string = '{} {} is'.format(amount, base.upper())
out_string = '{} {} is'.format(amount_in, base.upper())

unsupported_currencies = []
for target in targets:
Expand Down Expand Up @@ -259,10 +259,10 @@ def update_rates(bot):

@plugin.command('cur', 'currency', 'exchange')
@plugin.example('.cur 100 usd in btc cad eur',
r'100\.0 USD is [\d\.]+ BTC, [\d\.]+ CAD, [\d\.]+ EUR',
r'100 USD is [\d\.]+ BTC, [\d\.]+ CAD, [\d\.]+ EUR',
re=True, online=True, vcr=True)
@plugin.example('.cur 100 usd in btc cad eur can aux',
r'100\.0 USD is [\d\.]+ BTC, [\d\.]+ CAD, [\d\.]+ EUR, \(unsupported: CAN, AUX\)',
r'100 USD is [\d\.]+ BTC, [\d\.]+ CAD, [\d\.]+ EUR, \(unsupported: CAN, AUX\)',
re=True, online=True, vcr=True)
@plugin.output_prefix(PLUGIN_OUTPUT_PREFIX)
def exchange_cmd(bot, trigger):
Expand Down

0 comments on commit 181f9da

Please sign in to comment.