Jump to content


Photo

Formatar Moeda


  • Faça o login para participar
1 reply to this topic

#1 pr0gr4m4d0r

pr0gr4m4d0r

    Turista

  • Usuários
  • 46 posts
  • Sexo:Não informado

Posted 06/12/2005, 15:29

Nao achei no forum :(

Gostaria de ao ir digitando ja fosse assumindo os valores formatado do tipo MOEDA.

Ou Seja, digita 1000 e ja fica 10,00 automaticamente, na hora que vai digitando vai formatando!

alguem pode me ajudar?

obrigado!!!

#2 pr0gr4m4d0r

pr0gr4m4d0r

    Turista

  • Usuários
  • 46 posts
  • Sexo:Não informado

Posted 06/12/2005, 16:06

Opa, achei:

html:

<input name="frmValor" type="text" id="frmValor" style="width: 150px;" title="Informe o valor com os centavos." onKeyDown='FormataValor("frmValor", 13, event)' maxlength="13" alt="Informe o valor com os centavos.">

java script:

function FormataValor(campo,tammax,teclapres) {
var tecla = teclapres.keyCode;
vr = document.form[campo].value;
vr = vr.replace( "/", "" );
vr = vr.replace( "/", "" );
vr = vr.replace( ",", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
tam = vr.length;

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 <= 2 ){
document.form[campo].value = vr ; }
if ( (tam > 2) && (tam <= 5) ){
document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
if ( (tam >= 9) && (tam <= 11) ){
document.form[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
document.form[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 - 2, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
document.form[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 ) ;}
}
}




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq