Изменена обрезка символов после плавающей запятой

This commit is contained in:
Данил 2023-06-01 15:16:37 +03:00
parent 36bd104438
commit de390cc995
No known key found for this signature in database
GPG key ID: 5051BCD5AB064A7B

13
main.py
View file

@ -4,6 +4,7 @@ import json
import hashlib import hashlib
import logging import logging
import string
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
import requests import requests
@ -75,6 +76,16 @@ class CurrencyConverter:
if not self.ddgapi(): if not self.ddgapi():
self.coinapi() 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: def ddgapi(self) -> bool:
"""Get data from DuckDuckGo's currency API """Get data from DuckDuckGo's currency API
@ -161,7 +172,7 @@ async def currency(inline_query: InlineQuery) -> None:
result = ( result = (
f'{conv.amount} {conv.from_currency} = ' 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: except Exception as ex: