comparison app/model/Zusatzwert.js @ 1119:b73f9a976c82

Exponential notation without tampering numbers. Rounding is done by the server. Thus, the client should not fix the number of digits, except only for rendering.
author Tom Gottfried <tom@intevation.de>
date Mon, 23 May 2016 16:00:50 +0200
parents 1d20cec263ee
children 52bf58630e58
comparison
equal deleted inserted replaced
1118:ea5774447e49 1119:b73f9a976c82
24 }, { 24 }, {
25 name: 'probeId' 25 name: 'probeId'
26 }, { 26 }, {
27 name: 'pzsId' 27 name: 'pzsId'
28 }, { 28 }, {
29 name: 'nwgZuMesswert', 29 name: 'nwgZuMesswert'
30 serialize: function(v) {
31 if (v.indexOf(',') > 0) {
32 v = v.replace(',', '.');
33 return v;
34 }
35 return v;
36 },
37 convert: function(value) {
38 if (!value || value === '') {
39 return value;
40 }
41 var valueString = value.toString();
42 if (valueString.indexOf('E') > 0) {
43 valueString = valueString.replace('E', 'e');
44 }
45 var tmp;
46 if (valueString.indexOf('e') > 0) {
47 tmp = valueString;
48 }
49 else {
50 // Currently not locale friendly...
51 if (valueString.indexOf(',') > 0) {
52 valueString = valueString.replace(',', '.');
53 }
54 tmp = parseFloat(valueString).toExponential();
55 }
56 var parts = tmp.split('e');
57 if (parts[0].indexOf('.') > 0) {
58 var floatPart = parseFloat(parts[0]);
59 var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
60 parts[0] = floatPart.toFixed(2).replace('.', separator);
61 }
62 else if (parts[0].indexOf(',') < 0) {
63 parts[0] = parts[0] + ',00';
64 }
65 var intPart = parseInt(parts[1]);
66 if (intPart < 10 && intPart >= 0) {
67 parts[1] = '+0' + parseInt(parts[1]);
68 }
69 else if (intPart < 0 && intPart > -10) {
70 parts[1] = parts[1].replace('-', '-0');
71 }
72 return parts[0] + 'e' + parts[1];
73 }
74 }, { 30 }, {
75 name: 'messwertPzs', 31 name: 'messwertPzs'
76 serialize: function(v) {
77 if (v.indexOf(',') > 0) {
78 v = v.replace(',', '.');
79 return v;
80 }
81 return v;
82 },
83 convert: function(value) {
84 if (!value || value === '') {
85 return value;
86 }
87 var valueString = value.toString();
88 if (valueString.indexOf('E') > 0) {
89 valueString = valueString.replace('E', 'e');
90 }
91 var tmp;
92 if (valueString.indexOf('e') > 0) {
93 tmp = valueString;
94 }
95 else {
96 // Currently not locale friendly...
97 if (valueString.indexOf(',') > 0) {
98 valueString = valueString.replace(',', '.');
99 }
100 tmp = parseFloat(valueString).toExponential();
101 }
102 var parts = tmp.split('e');
103 if (parts[0].indexOf('.') > 0) {
104 var floatPart = parseFloat(parts[0]);
105 var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
106 parts[0] = floatPart.toFixed(2).replace('.', separator);
107 }
108 else if (parts[0].indexOf(',') < 0) {
109 parts[0] = parts[0] + ',00';
110 }
111 var intPart = parseInt(parts[1]);
112 if (intPart < 10 && intPart >= 0) {
113 parts[1] = '+0' + parseInt(parts[1]);
114 }
115 else if (intPart < 0 && intPart > -10) {
116 parts[1] = parts[1].replace('-', '-0');
117 }
118 return parts[0] + 'e' + parts[1];
119 }
120 }, { 32 }, {
121 name: 'messfehler', 33 name: 'messfehler',
122 type: 'float' 34 type: 'float'
123 }, { 35 }, {
124 name: 'letzteAenderung', 36 name: 'letzteAenderung',

http://lada.wald.intevation.org