changeset 1069:1d20cec263ee

Fixed exponential number format.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 31 Mar 2016 11:44:03 +0200
parents 096d552508cd
children 33927274f013
files app/model/Messwert.js app/model/Zusatzwert.js
diffstat 2 files changed, 48 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/app/model/Messwert.js	Thu Mar 24 09:49:28 2016 +0100
+++ b/app/model/Messwert.js	Thu Mar 31 11:44:03 2016 +0200
@@ -59,8 +59,18 @@
             var parts = tmp.split('e');
             if (parts[0].indexOf('.') > 0) {
                 var floatPart = parseFloat(parts[0]);
-                var separator = floatPart.toLocaleString().replace(/[-\d]/g, '');
-                parts[0] = floatPart.toFixed(3).replace('.', separator);
+                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
+                parts[0] = floatPart.toFixed(2).replace('.', separator);
+            }
+            else if (parts[0].indexOf(',') < 0) {
+                parts[0] = parts[0] + ',00';
+            }
+            var intPart = parseInt(parts[1]);
+            if (intPart < 10 && intPart >= 0) {
+                parts[1] = '+0' + parseInt(parts[1]);
+            }
+            else if (intPart < 0 && intPart > -10) {
+                parts[1] = parts[1].replace('-', '-0');
             }
             return parts[0] + 'e' + parts[1];
         }
@@ -110,7 +120,18 @@
             var parts = tmp.split('e');
             if (parts[0].indexOf('.') > 0) {
                 var floatPart = parseFloat(parts[0]);
-                parts[0] = floatPart.toLocaleString();
+                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
+                parts[0] = floatPart.toFixed(2).replace('.', separator);
+            }
+            else if (parts[0].indexOf(',') < 0) {
+                parts[0] = parts[0] + ',00';
+            }
+            var intPart = parseInt(parts[1]);
+            if (intPart < 10 && intPart >= 0) {
+                parts[1] = '+0' + parseInt(parts[1]);
+            }
+            else if (intPart < 0 && intPart > -10) {
+                parts[1] = parts[1].replace('-', '-0');
             }
             return parts[0] + 'e' + parts[1];
         }
--- a/app/model/Zusatzwert.js	Thu Mar 24 09:49:28 2016 +0100
+++ b/app/model/Zusatzwert.js	Thu Mar 31 11:44:03 2016 +0200
@@ -56,8 +56,18 @@
             var parts = tmp.split('e');
             if (parts[0].indexOf('.') > 0) {
                 var floatPart = parseFloat(parts[0]);
-                var separator = floatPart.toLocaleString().replace(/[-\d]/g, '');
-                parts[0] = floatPart.toFixed(3).replace('.', separator);
+                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
+                parts[0] = floatPart.toFixed(2).replace('.', separator);
+            }
+            else if (parts[0].indexOf(',') < 0) {
+                parts[0] = parts[0] + ',00';
+            }
+            var intPart = parseInt(parts[1]);
+            if (intPart < 10 && intPart >= 0) {
+                parts[1] = '+0' + parseInt(parts[1]);
+            }
+            else if (intPart < 0 && intPart > -10) {
+                parts[1] = parts[1].replace('-', '-0');
             }
             return parts[0] + 'e' + parts[1];
         }
@@ -92,8 +102,18 @@
             var parts = tmp.split('e');
             if (parts[0].indexOf('.') > 0) {
                 var floatPart = parseFloat(parts[0]);
-                var separator = floatPart.toLocaleString().replace(/[-\d]/g, '');
-                parts[0] = floatPart.toFixed(3).replace('.', separator);
+                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
+                parts[0] = floatPart.toFixed(2).replace('.', separator);
+            }
+            else if (parts[0].indexOf(',') < 0) {
+                parts[0] = parts[0] + ',00';
+            }
+            var intPart = parseInt(parts[1]);
+            if (intPart < 10 && intPart >= 0) {
+                parts[1] = '+0' + parseInt(parts[1]);
+            }
+            else if (intPart < 0 && intPart > -10) {
+                parts[1] = parts[1].replace('-', '-0');
             }
             return parts[0] + 'e' + parts[1];
         }

http://lada.wald.intevation.org