Ho questa funzione:
function formatIt(s) {
var oldfirst="";
var second="";
var newfirst="";
var y=0;
var result="";
if (s.indexOf('.')>-1) {
oldfirst = s.substring(0, s.indexOf('.'));
second = s.substr(s.indexOf('.')+1, 2);
for (var i=oldfirst.length-1; i>=0; i--) {
if (y%3==0 && y>0) newfirst='.'+newfirst;
newfirst = oldfirst.charAt(i) + newfirst;
y++;
}
result=newfirst+','+second;
}
else {
for (var i=s.length-1; i>=0; i--) {
if (y%3==0 && y>0) newfirst='.'+newfirst;
newfirst = s.charAt(i) + newfirst;
y++;
}
result = newfirst;
result = result + ',00';
}
return result;
}
Il problema č che fino ad un milione funziona. Superato il milione non torna e mi toglie 3 cifre. Sapete aiutarmi?