aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-12-13 16:12:34 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2017-12-15 07:30:35 +0100
commitbf7d159d55784836f79184f505f9fc44a82b92fa (patch)
tree6a17baab3b865831540fa4145856e94a3f75b015 /src
parent206bbfa8424442d49dd62520255aaf47f788f663 (diff)
downloadee-python-bf7d159d55784836f79184f505f9fc44a82b92fa.tar.gz
ee-python-bf7d159d55784836f79184f505f9fc44a82b92fa.tar.bz2
ee-python-bf7d159d55784836f79184f505f9fc44a82b92fa.tar.xz
ee-python-bf7d159d55784836f79184f505f9fc44a82b92fa.zip
o Adding option for rounding E-series values.
Diffstat (limited to 'src')
-rw-r--r--src/ee/formatting/__init__.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/ee/formatting/__init__.py b/src/ee/formatting/__init__.py
index 5e612fe..46e99f7 100644
--- a/src/ee/formatting/__init__.py
+++ b/src/ee/formatting/__init__.py
@@ -8,10 +8,16 @@ __all__ = [
class ESeries(object):
+ ROUND_CLOSEST = 1
+ ROUND_UP = 2
+ ROUND_DOWN = 3
+
def __init__(self, series):
self.series = series
- def closest(self, value):
+ def closest(self, value, round_direction = ROUND_CLOSEST):
+ if round_direction != ESeries.ROUND_CLOSEST:
+ raise NotImplementedError("Only closest rounding is implemented for now")
e = math.floor(math.log10(value))
value = float(value / (10 ** e))
@@ -56,14 +62,6 @@ e48 = ESeries(_e_series_48)
e96 = ESeries(_e_series_96)
e192 = ESeries(_e_series_192)
-
-def e_series_find_closest(value):
- e = math.floor(math.log10(value))
- value = float(value / (10 ** e))
-
- return min(series, key=lambda v: abs(v - value)) * 10 ** e
-
-
import numpy