From 839d16fdf062d1675430d669025772b36ef500f8 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Wed, 21 Nov 2018 21:09:14 +0000
Subject: [PATCH] Added dec formatting and checking multiple 0 answers.
---
aoi_gen/Variable.py | 26 +++++++++++++++++++++++++-
1 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/aoi_gen/Variable.py b/aoi_gen/Variable.py
index 967ec41..4c7c63b 100644
--- a/aoi_gen/Variable.py
+++ b/aoi_gen/Variable.py
@@ -90,7 +90,7 @@
elif type == "prefix":
return PrefixFloatFormatter(arglist)
elif type == "dec" or type == "decimal":
- return EngFloatFormatter(arglist) # fallback to engineering
+ return DecFloatFormatter(arglist)
else:
return None
@@ -113,6 +113,30 @@
def getValue(self, string):
return string
+class DecFloatFormatter(FormatterFactory):
+ def __init__(self, formatparameters):
+ if len(formatparameters) != 1:
+ raise Exceptions.WrongParameters("Dec format accept only one argument")
+ self.precision = int(formatparameters[0])
+
+ def toFormat(self, num):
+ try:
+ num = float(num)
+ except ValueError:
+ raise ValueError
+ except TypeError:
+ raise ValueError
+
+
+ return (
+ ("{:." + str(self.precision - 1) + "f}").format(num).replace(".", ",\!")
+ )
+
+ def getValue(self, num):
+ val = ("{:." + str(self.precision - 1) + "f}").format(num)
+ return float(val)
+
+
class SciFloatFormatter(FormatterFactory):
def __init__(self, formatparameters):
--
Gitblit v1.8.0