Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Formatacao De Numeros


Mário Miranda
 Share

Question

Bom dia. Tenho esse esquema que faz a formatação de números:

function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,\"0123456789\");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1; }

if (tecla == 8 )
{ tam = tam - 1; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + \".\" + vr.substr( tam - dec, tam ); }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + \".\" + vr.substr( tam - 5, 3 ) + \".\" + vr.substr( tam - dec, tam );
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + \".\" + vr.substr( tam - 8, 3 ) + \".\" + vr.substr( tam - 5, 3 ) + \".\" + vr.substr( tam - dec, tam ); }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + \".\" + vr.substr( tam - 11, 3 ) + \".\" + vr.substr( tam - 8, 3 ) + \".\" + vr.substr( tam - 5, 3 ) + \".\" + vr.substr( tam - dec, tam ); }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + \".\" + vr.substr( tam - 14, 3 ) + \".\" + vr.substr( tam - 11, 3 ) + \".\" + vr.substr( tam - 8, 3 ) + \".\" + vr.substr( tam - 5, 3 ) + \".\" + vr.substr( tam - 2, tam );}
}

}
Ele coloca ponto nas casas. Mas eu gostaria que, quando o numero fosse a partir de mil, o número ficasse assim 1000.00 e nãp assim 1.000.00 (que é como o esquema deixa). Não sei o que eu tenho que alterar. Desde já agradeço a a ajuda de todos. Pessoal. Desculpem. Consegui resolver já. Era bem simples. Nesta parte:
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + \".\" + vr.substr( tam - 5, 3 ) + \".\" + vr.substr( tam - dec, tam );
}
Teria que deixar assim
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + \"\" + vr.substr( tam - 5, 3 ) + \".\" + vr.substr( tam - dec, tam );
}

Desculpem a falta de atenção.
Até mais

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...