Here’s the solution I come up with. Unfortunately much more verbose than I expected. I have a feeling this could be done with much less code using regular expression fully but I ran into a brick wall when tried to use {1-3} in the regular expression. I couldn’t get Servoy to accept it!
Maybe there’s an issue here.
So here’s an acceptable solution, albeit a little verbose, but abstract solution:
// format the labels with the thousand separator!
// gather the labels to format in an Array
var labelsToFormat = [elements['lbl_credit_acum'], elements['lbl_inv_acum']]
var re = /(\d\d\d)$/;
var idx = 0;
var newStr = [];
var tempStr = '';
var head = '';
var tail = '';
for ( var i=0; i < labelsToFormat.length; i++ ) {
tempStr = labelsToFormat[i].text;
idx = tempStr.search(re);
while (idx != -1) {
head = tempStr.substr(0,idx);
tail = tempStr.substr(idx);
if ( head ) {
newStr.unshift('.' + tail);
}
else {
newStr.unshift(tail);
break;
}
tempStr = head;
idx = tempStr.search(re);
}
newStr.unshift(head);
labelsToFormat[i].text = newStr.join('');
newStr = [];
}