MCPcopy Create free account
hub / github.com/Rello/analytics / normalizeNumberString

Function normalizeNumberString

js/visualization.js:140–172  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

138
139 compareValues: function (a, b, fn) {
140 function normalizeNumberString(str) {
141 if (typeof str !== "string") return str;
142 str = str.trim();
143 const hasComma = str.includes(',');
144 const hasDot = str.includes('.');
145
146 if (hasComma && hasDot) {
147 if (str.lastIndexOf(',') > str.lastIndexOf('.')) {
148 // comma as decimal separator
149 str = str.replace(/\./g, '');
150 str = str.replace(',', '.');
151 } else {
152 // dot as decimal separator
153 str = str.replace(/,/g, '');
154 }
155 } else if (hasComma) {
156 const idx = str.lastIndexOf(',');
157 const digits = str.length - idx - 1;
158 if (digits <= 2) {
159 str = str.replace(',', '.');
160 } else {
161 str = str.replace(/,/g, '');
162 }
163 } else if (hasDot) {
164 const idx = str.lastIndexOf('.');
165 const digits = str.length - idx - 1;
166 if (digits > 2) {
167 str = str.replace(/\./g, '');
168 }
169 }
170
171 return str.replace(/\s/g, '');
172 }
173
174 const normalizedA = OCA.Analytics.Visualization.normalizeThresholdString(a);
175 const normalizedB = OCA.Analytics.Visualization.normalizeThresholdString(b);

Callers 1

visualization.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected