mirror of
https://github.com/Redume/Shirino.git
synced 2024-11-24 01:06:21 +03:00
Изменена обрезка символов после плавающей запятой
This commit is contained in:
parent
36bd104438
commit
de390cc995
1 changed files with 12 additions and 1 deletions
13
main.py
13
main.py
|
@ -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:
|
||||||
|
|
Loading…
Add table
Reference in a new issue