function money(value, currency) { /* Formatar um valor com o símbolo de moeda corrente, ex.: R$ 1.000,00 value = valor a ser formatado currency = código moeda (ex.: 1046|1033|2057|11274|3082, real,dólar,libra,peso,euro,respect.) */ if (currency == null) currency = 1046; value = Math.ceil(value - 0.5); value = value.toString(); if (value.length < 3) value = "0" + value; if (value.length < 3) value = "0" + value; switch (currency) { case 1046: if (value == 0) { value = "R$0,00"; } else { if (value.length>2) { if (value.length<=5) { value = "R$" + insStr(value, value.length - 2, ","); } else { value = "R$" + insStr(value, value.length - 2, ","); var posicao = value.indexOf(","); var subvalue = value.substring(0,posicao-3); var valortotal; if (subvalue!="" && subvalue!=null && subvalue.length > 2) { valortotal = subvalue+"."+value.substring(subvalue.length,value.length); } value = valortotal; } } else { value = "R$0,"+value; } } break; case 1033: value = "U$" + insStr(value, value.length - 2, "."); break; case 2057: value = "£" + insStr(value, value.length - 2, ","); break; case 11274: value = "$" + insStr(value, value.length - 2, ","); break; case 3082: value = insStr(value, value.length - 2, ".") + "€"; break; } return value; function insStr(string, position, chars) { /* Inserir carateres em determinada posição da string */ return string.substring(0, position) + chars + string.substring(position, string.length); } }