Hola
pablo1111, este lo hice hace ya un tiempo, se me es bastante útil, espero les sea a ustedes. Sirve para N dígitos.
Código Javascript
:
Ver originalfunction formatoMoneda(number) {
var number1 = number.toString(), result = '', estado = true;
if (parseInt(number1) < 0) {
estado = false;
number1 = parseInt(number1) * -1;
number1 = number1.toString();
}
if (number1.indexOf(',') == -1) {
while (number1.length > 3) {
result = '.' + '' + number1.substr(number1.length - 3) + '' + result;
number1 = number1.substring(0, number1.length - 3);
}
result = number1 + result;
if (estado == false) {
result = '-' + result;
}
}
else {
var pos = number1.indexOf(',');
var numberInt = number1.substring(0, pos);
var numberDec = number1.substring(pos, number1.length);
while (numberInt.length > 3) {
result = '.' + '' + numberInt.substr(numberInt.length - 3) + '' + result;
numberInt = numberInt.substring(0, numberInt.length - 3);
}
result = numberInt + result + numberDec;
if (estado == false) {
result = '-' + result;
}
}
return result;
}
Saludos.