Forráskód Böngészése

Add RR with Value

JoostSijm 6 éve
szülő
commit
252138b5e9
1 módosított fájl, 26 hozzáadás és 0 törlés
  1. 26 0
      rr.py

+ 26 - 0
rr.py

@@ -0,0 +1,26 @@
+"""Easy calc functions"""
+
+class Value(int):
+    """A value parser"""
+
+    def __new__(cls, value):
+        if isinstance(value, str):
+            value = value.replace('t', '000000000000')
+            value = value.replace('k', '000')
+            value = value.replace('.', '')
+            value = int(value)
+        return super(Value, cls).__new__(cls, value)
+
+    def __repr__(self):
+        str_format = '{:,}'.format(self)
+        new_str = ''
+        for i in range(len(str_format), 0, -4):
+            if str_format[i-4:i] == ',000':
+                new_str = 'k' + new_str
+            else:
+                new_str = str_format[:i] + new_str
+                break
+
+        new_str = new_str.replace('kkkk', 't') 
+        new_str = new_str.replace(',', '.') 
+        return new_str