I'm using a math javascript and I'm having some trouble getting it to replace commas for dots and dots for commas. I can get the comma for the thousands seperator to change but can't manage to get the decimal point to turn into a comma. I tried a number of suggestions from other posts with no joy. The goal is to achieve number formatting for a Greek application.
Here's what I have:
function addCommas(nStr) {
nStr += '';
x = nStr.split(',');
x1 = x[0];
x2 = x.length > 1 ? ',' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
x2 = x.replace(/,([^,]*)$/, ".$1");
}
return x1 + x2;
}
function addCommas2(nStr, nztr) {
var sam = nStr.toFixed(nztr);
return sam;
}
function roundNumber(num, dec) {
return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}