aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorArun Isaac2023-01-19 18:05:46 +0000
committerArun Isaac2023-01-19 18:09:34 +0000
commit53fd9b13d0ffb9f992b571ab5d6ddda58f7b9af3 (patch)
treeecca19da2001c4abae95038efbb2ba7e04cdd851 /gn3
parent13a7c5cf58a1b456a50d69ea761f7106d2fe4978 (diff)
downloadgenenetwork3-53fd9b13d0ffb9f992b571ab5d6ddda58f7b9af3.tar.gz
search: Use decimals, not floats, to manipulate range limits.
Decimals are exact and do not introduce tiny errors in the range limits like floats are wont to do. * gn3/api/search.py: Import Decimal from decimal. (apply_si_suffix): Use decimals, not floats, to manipulate range limits.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/api/search.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py
index 2c11d4c..820b74b 100644
--- a/gn3/api/search.py
+++ b/gn3/api/search.py
@@ -1,6 +1,7 @@
"""Search using Xapian index."""
from collections import namedtuple
+from decimal import Decimal
import gzip
import json
from functools import partial, reduce
@@ -151,7 +152,7 @@ def apply_si_suffix(location: str) -> int:
"""Apply SI suffixes kilo, mega, giga and convert to bases."""
suffixes = {"k": 3, "m": 6, "g": 9}
if location[-1] in suffixes:
- return int(float(location[:-1])*10**suffixes[location[-1].lower()])
+ return int(Decimal(location[:-1])*10**suffixes[location[-1].lower()])
else:
return int(location)