comparison app/model/Messwert.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 14c130767e44
children 3b4dcc83a21b
comparison
equal deleted inserted replaced
1118:ea5774447e49 1119:b73f9a976c82
24 }, { 24 }, {
25 name: 'messungsId' 25 name: 'messungsId'
26 }, { 26 }, {
27 name: 'messgroesseId' 27 name: 'messgroesseId'
28 }, { 28 }, {
29 name: 'messwert', 29 name: 'messwert'
30 serialize: function(v) {
31 if (!v || v === '') {
32 return v;
33 }
34 if (v.indexOf(',') > 0) {
35 v = v.replace(',', '.');
36 return v;
37 }
38 return v;
39 },
40 convert: function(value) {
41 if (!value || value === '') {
42 return value;
43 }
44 var valueString = value.toString();
45 if (valueString.indexOf('E') > 0) {
46 valueString = valueString.replace('E', 'e');
47 }
48 var tmp;
49 if (valueString.indexOf('e') > 0) {
50 tmp = valueString;
51 }
52 else {
53 // Currently not locale friendly...
54 if (valueString.indexOf(',') > 0) {
55 valueString = valueString.replace(',', '.');
56 }
57 tmp = parseFloat(valueString).toExponential();
58 }
59 var parts = tmp.split('e');
60 if (parts[0].indexOf('.') > 0) {
61 var floatPart = parseFloat(parts[0]);
62 var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
63 parts[0] = floatPart.toFixed(2).replace('.', separator);
64 }
65 else if (parts[0].indexOf(',') < 0) {
66 parts[0] = parts[0] + ',00';
67 }
68 var intPart = parseInt(parts[1]);
69 if (intPart < 10 && intPart >= 0) {
70 parts[1] = '+0' + parseInt(parts[1]);
71 }
72 else if (intPart < 0 && intPart > -10) {
73 parts[1] = parts[1].replace('-', '-0');
74 }
75 return parts[0] + 'e' + parts[1];
76 }
77 }, { 30 }, {
78 name: 'messwertNwg', 31 name: 'messwertNwg',
79 convert: function(v) { 32 convert: function(v) {
80 if (!v) { 33 if (!v) {
81 return null; 34 return null;
85 // defaultValue: null 38 // defaultValue: null
86 }, { 39 }, {
87 name: 'messfehler', 40 name: 'messfehler',
88 type: 'float' 41 type: 'float'
89 }, { 42 }, {
90 name: 'nwgZuMesswert', 43 name: 'nwgZuMesswert'
91 serialize: function(v) {
92 if (!v || v === '') {
93 return v;
94 }
95 if (v.indexOf(',') > 0) {
96 v = v.replace(',', '.');
97 return v;
98 }
99 return v;
100 },
101 convert: function(value) {
102 if (!value || value === '') {
103 return value;
104 }
105 var valueString = value.toString();
106 if (valueString.indexOf('E') > 0) {
107 valueString = valueString.replace('E', 'e');
108 }
109 var tmp;
110 if (valueString.indexOf('e') > 0) {
111 tmp = valueString;
112 }
113 else {
114 // Currently not locale friendly...
115 if (valueString.indexOf(',') > 0) {
116 valueString = valueString.replace(',', '.');
117 }
118 tmp = parseFloat(valueString).toExponential();
119 }
120 var parts = tmp.split('e');
121 if (parts[0].indexOf('.') > 0) {
122 var floatPart = parseFloat(parts[0]);
123 var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
124 parts[0] = floatPart.toFixed(2).replace('.', separator);
125 }
126 else if (parts[0].indexOf(',') < 0) {
127 parts[0] = parts[0] + ',00';
128 }
129 var intPart = parseInt(parts[1]);
130 if (intPart < 10 && intPart >= 0) {
131 parts[1] = '+0' + parseInt(parts[1]);
132 }
133 else if (intPart < 0 && intPart > -10) {
134 parts[1] = parts[1].replace('-', '-0');
135 }
136 return parts[0] + 'e' + parts[1];
137 }
138 }, { 44 }, {
139 name: 'mehId' 45 name: 'mehId'
140 }, { 46 }, {
141 name: 'grenzwertueberschreitung', 47 name: 'grenzwertueberschreitung',
142 type: 'boolean' 48 type: 'boolean'

http://lada.wald.intevation.org