From 2573253e2be8602b7ad277a96630e890bd8f118d Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 1 Jun 2023 17:07:20 +0400 Subject: [PATCH] Rounding instead of flooring --- main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 3f5fc2e..dbed455 100644 --- a/main.py +++ b/main.py @@ -93,13 +93,11 @@ class CurrencyConverter: # it is an integer like 81.0 return - # first non-zero + - # 3 digits after zeroes or after the point - # (settings.ndigit = 3 by default) - after_point = after_point[:fnz + settings.ndigits] + # how many digits should be after the point: + # ndigits (3 by default) after first non-zero + ndigits = fnz + settings.ndigits - rounded = f'{str_amount[:point]}.{after_point}' - self.conv_amount = float(rounded) + self.conv_amount = round(self.conv_amount, ndigits) def ddgapi(self) -> bool: """Get data from DuckDuckGo's currency API