From de390cc9951db3db09fda60b0bd87049b087175f Mon Sep 17 00:00:00 2001 From: Redume Date: Thu, 1 Jun 2023 15:16:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B5=D0=B7=D0=BA=D0=B0=20=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=D0=B2=D0=BE=D0=BB=D0=BE=D0=B2=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=20=D0=BF=D0=BB=D0=B0=D0=B2=D0=B0=D1=8E=D1=89=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=B7=D0=B0=D0=BF=D1=8F=D1=82=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index ee7802e..f842b01 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import json import hashlib import logging +import string from typing import Any, Dict, List, Optional import requests @@ -75,6 +76,16 @@ class CurrencyConverter: if not self.ddgapi(): self.coinapi() + s = f'{self.conv_amount}' + point = s.find(".") + + a = s[point+1:] + fnz = min([a.index(i) for i in string.digits[1:] if i in a], default=-1) + if fnz == -1: + self.conv_amount = int(float(s)) + + self.conv_amount = s[:point] + '.' + a[:fnz+3] + def ddgapi(self) -> bool: """Get data from DuckDuckGo's currency API @@ -161,7 +172,7 @@ async def currency(inline_query: InlineQuery) -> None: result = ( f'{conv.amount} {conv.from_currency} = ' - f'{math.floor(conv.conv_amount)} {conv.conv_currency}' + f'{conv.conv_amount} {conv.conv_currency}' ) except Exception as ex: