diff app/model/Messwert.js @ 1069:1d20cec263ee

Fixed exponential number format.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 31 Mar 2016 11:44:03 +0200
parents 7fa853864d9b
children 9a0f7712f366
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];
         }

http://lada.wald.intevation.org