From 3bd533d71eeb925950f1be7034cf0bed1fb8be71 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Wed, 16 Aug 2023 08:51:10 -0700 Subject: Fix percent change display. --- market.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/market.py b/market.py index d5f3c76..3eefd5b 100755 --- a/market.py +++ b/market.py @@ -130,9 +130,9 @@ def update_exchanges(state: State) -> State: return State(state.stocks, exchanges) -def format_delta(stock: Stock, percent: bool = False) -> str: - sign = "+" if stock.change_point >= 0 else "-" - change = f"{sign}{abs(stock.change_point)}{'%' if percent else ''}" +def format_delta(delta: float, percent: bool = False) -> str: + sign = "+" if delta >= 0 else "-" + change = f"{sign}{abs(delta)}{'%' if percent else ''}" return change @@ -257,8 +257,9 @@ class MarketApp(App): table.clear(columns=True) table.add_columns("Stock", "Price($)", "Change($)", "%") for stock in self.state.stocks: - table.add_row(stock.sticker, stock.price, format_delta(stock), - format_delta(stock, percent=True)) + table.add_row(stock.sticker, stock.price, + format_delta(stock.change_point), + format_delta(stock.change_percent, percent=True)) for exchange in self.state.exchanges: table.add_row(format_exchange_name(exchange), exchange.rate, "", "") -- cgit v1.2.3