I'm not terribly confident that my answer wont be met with rolling eyes or hostility - it certainly is fairly sloppy - though it does
appear to at least work.
I guess you could always (shudder) examine the returned string representation of the date as a means of guessing/determining the appropriate routine to use to convert the number.
When run, the output is
3,141,592.653589793
3141592,653589793
<!DOCTYPE html>
<html>
<head>
<script>
function convNum()
{
var inNum = 1000000 * 3.141592653589793;
document.getElementById('ukUs').innerHTML = toUkUs(inNum);
document.getElementById('hung').innerHTML = toHung(inNum);
}
function toHung(num)
{
var str = String(num);
return str.replace('.', ',');
}
function toUkUs(num)
{
var str = thousandSeparator(num,',');
var n=str.indexOf(".");
var preDec = str.substring(0,n);
var postDec ='';
for (i=n; i<str.length; i++)
{
if (str.charAt(i) != ',')
postDec += str.charAt(i);
}
return preDec + postDec;
}
function thousandSeparator(n,sep) {
var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'), sValue=n+'';
if (sep === undefined) {sep=',';}
while(sRegExp.test(sValue)) {
sValue = sValue.replace(sRegExp, '$1'+sep+'$2');
}
return sValue;
}
</script>
</head>
<body>
<span>1000000 * π</span><button onclick="convNum();">Get number</button><br>
<div id="ukUs"></div>
<div id="hung"></div>
</body>
</html>