Duvida ____Urgente

Ola, Bom dia,
tenho uma duvida:Preciso fazer uma funcao que parametrize a quantidade de casas decimais.Por exemplo:
tenho um número 2,5 e gostaria que tivesse uma funcao que ja faria automatico quando precisasse de ser alterado para 2,52 por exemplo, adicionando só um caractere.

Fico aguardando
Obrigada

Você postou em “Outras linguagens”, que linguagem você está com dúvidas?

Isso que eu chamo de pergunta pertinente :smiley:

a linguagem que estou usando é Java Script

isso ai funciona, para Java, php, c e c++ :slight_smile: ja ajuda

Fiz o teste e parece que ele nao aceitou essa funcao.
Voces teriam outra opcao?

Posta seu codigo entre as tags code

[code] function formataValor(Valor,nCsDec){
var sValor=Valor + "";
var tam = sValor.length
var ponto = sValor.length

sValor = sValor.replace( “.”, “,” );
alert(sValor);
ponto = sValor.indexOf(’,’);

if(ponto != -1) {
sValor = sValor.substr( 0, ponto + nCsDec + 1 );
if ( (ponto > 3) && (ponto < 7) ) sValor = sValor.substr( 0, ponto - 3 ) + ‘.’ + sValor.substr( ponto - 3,10000 );
if ( (ponto >= 7) && (ponto < 10) ) sValor = sValor.substr( 0, ponto - 6 ) + ‘.’ + sValor.substr( ponto - 6, 3 ) + ‘.’ + sValor.substr( ponto - 3,10000 );
if ( (ponto >= 10) && (ponto < 13) ) sValor = sValor.substr( 0, ponto - 9 ) + ‘.’ + sValor.substr( ponto - 9, 3 ) + ‘.’ + sValor.substr( ponto - 6, 3 ) + ‘.’ + sValor.substr( ponto - 3,10000 );
//if ( (ponto >= 13) && (ponto < 16) ) sValor = sValor.substr( 0, ponto - 12 ) + ‘.’ + sValor.substr( ponto - 12, 3 )+ ‘.’ + sValor.substr( ponto - 9, 3 ) + ‘.’ + sValor.substr( ponto - 6, 3 ) + ‘.’ + sValor.substr( ponto - 3,10000 );
//if ( (ponto >= 16) && (ponto < 19) ) sValor = sValor.substr( 0, ponto - 15 ) + ‘.’ + sValor.substr( ponto - 15, 3 ) + ‘.’ + sValor.substr( ponto - 12, 3 )+ ‘.’ + sValor.substr( ponto - 9, 3 ) + ‘.’ + sValor.substr( ponto - 6, 3 ) + ‘.’ + sValor.substr( ponto - 3,10000 );

}

alert(sValor);
/*i

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 - 2, 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 ) ;}
}*/
}
// Função utilizada para alterar o conteudo de uma célula
// Retorna vazio

function insereLetra(idCell){
//alert(idCell);
var tecla = window.event.keyCode;
if (tecla == 13){
if(bAlterado){
if(emFoco.indexOf(‘b’) != -1) calcSpread(idCell);
else calcResult(idCell);
sValor = “”;
return;
}
}
var sVal = sValor;

switch(tecla){
case 48: sValor += "0";
alteraCelula(idCell,sValor);
break;
case 49: sValor += "1";
alteraCelula(idCell,sValor);
break;
case 50: sValor += "2";
alteraCelula(idCell,sValor);
break;
case 51: sValor += "3";
alteraCelula(idCell,sValor);
break;
case 52: sValor += "4";
alteraCelula(idCell,sValor);
break;
case 53: sValor += "5";
alteraCelula(idCell,sValor);
break;
case 54: sValor += "6";
alteraCelula(idCell,sValor);
break;
case 55: sValor += "7";
alteraCelula(idCell,sValor);
break;
case 56: sValor += "8";
alteraCelula(idCell,sValor);
break;
case 57: sValor += "9";
alteraCelula(idCell,sValor);
break;
case 96: sValor += "0";
alteraCelula(idCell,sValor);
break;
case 97: sValor += "1";
alteraCelula(idCell,sValor);
break;
case 98: sValor += "2";
alteraCelula(idCell,sValor);
break;
case 99: sValor += "3";
alteraCelula(idCell,sValor);
break;
case 100: sValor += "4";
alteraCelula(idCell,sValor);
break;
case 101: sValor += "5";
alteraCelula(idCell,sValor);
break;
case 102: sValor += "6";
alteraCelula(idCell,sValor);
break;
case 103: sValor += "7";
alteraCelula(idCell,sValor);
break;
case 104: sValor += "8";
alteraCelula(idCell,sValor);
break;
case 105: sValor += "9";
alteraCelula(idCell,sValor);
break;
case 110: sValor += ".";
alteraCelula(idCell,sValor);
break;
case 190: sValor += ".";
alteraCelula(idCell,sValor);
break;
case 188: sValor += ",";
alteraCelula(idCell,sValor);
break;
case 109: sValor += "-";
alteraCelula(idCell,sValor);
break;
case 107: sValor += "+";
alteraCelula(idCell,sValor);
break;
case 106: sValor += "*";
alteraCelula(idCell,sValor);
break;
case 111: sValor += "/";
alteraCelula(idCell,sValor);
break;
case 191: sValor += "/";
alteraCelula(idCell,sValor);
break;
case 16: sValor += "";
alteraCelula(idCell,sValor);
break;
/case 46: sValor += "" + String.fromCharCode(tecla);
alteraCelula(idCell,sValor);
break;
/
}
if(sVal != sValor) bAlterado = true;

}[/code]

Desculpe, estou iniciando em java script
Segue abaixo uma parte do codigo em js

function formataValor(Valor,nCsDec){
var sValor=Valor + “”;
var tam = sValor.length
var ponto = sValor.length

sValor = sValor.replace( ".", "," );
alert(sValor);
ponto = sValor.indexOf(',');

if(ponto != -1) {
	sValor =  sValor.substr( 0, ponto + nCsDec + 1 );
		if ( (ponto > 3) && (ponto < 7) )	sValor = sValor.substr( 0, ponto - 3 ) + '.' + sValor.substr( ponto - 3,10000 ); 
		if ( (ponto >= 7) && (ponto < 10) )	sValor = sValor.substr( 0, ponto - 6 ) + '.' + sValor.substr( ponto - 6, 3 ) + '.' + sValor.substr( ponto - 3,10000 ); 
	    if ( (ponto >= 10) && (ponto < 13) ) sValor =  sValor.substr( 0, ponto - 9 ) + '.' + sValor.substr( ponto - 9, 3 ) + '.' + sValor.substr( ponto - 6, 3 ) + '.' + sValor.substr( ponto - 3,10000 ); 
	    //if ( (ponto >= 13) && (ponto < 16) ) sValor =  sValor.substr( 0, ponto - 12 ) + '.' + sValor.substr( ponto - 12, 3 )+ '.' + sValor.substr( ponto - 9, 3 ) + '.' + sValor.substr( ponto - 6, 3 ) + '.' + sValor.substr( ponto - 3,10000 ); 
	    //if ( (ponto >= 16) && (ponto < 19) ) sValor =  sValor.substr( 0, ponto - 15 ) + '.' + sValor.substr( ponto - 15, 3 ) + '.' + sValor.substr( ponto - 12, 3 )+ '.' + sValor.substr( ponto - 9, 3 ) + '.' + sValor.substr( ponto - 6, 3 ) + '.' + sValor.substr( ponto - 3,10000 ); 
	
}

alert(sValor);
/*i

 	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 - 2, 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 ) ;}
}*/

}
// Função utilizada para alterar o conteudo de uma célula
// Retorna vazio

function insereLetra(idCell){
//alert(idCell);
var tecla = window.event.keyCode;
if (tecla == 13){
if(bAlterado){
if(emFoco.indexOf(‘b’) != -1) calcSpread(idCell);
else calcResult(idCell);
sValor = “”;
return;
}
}
var sVal = sValor;

switch(tecla){ 
	case 48: sValor += "0";
			alteraCelula(idCell,sValor);
			break;
	case 49: sValor += "1";
			alteraCelula(idCell,sValor);
			break;
	case 50: sValor += "2";
			alteraCelula(idCell,sValor);
			break;
	case 51: sValor += "3";
			alteraCelula(idCell,sValor);
			break;
	case 52: sValor += "4";
			alteraCelula(idCell,sValor);
			break;	
	case 53: sValor += "5";
			alteraCelula(idCell,sValor);
			break;
	case 54: sValor += "6";
			alteraCelula(idCell,sValor);
			break;
	case 55: sValor += "7";
			alteraCelula(idCell,sValor);
			break;
	case 56: sValor += "8";
			alteraCelula(idCell,sValor);
			break;
	case 57: sValor += "9";
			alteraCelula(idCell,sValor);
			break;		
	case 96: sValor += "0";
			alteraCelula(idCell,sValor);
			break;
	case 97: sValor += "1";
			alteraCelula(idCell,sValor);
			break;
	case 98: sValor += "2";
			alteraCelula(idCell,sValor);
			break;
	case 99: sValor += "3";
			alteraCelula(idCell,sValor);
			break;
	case 100: sValor += "4";
			alteraCelula(idCell,sValor);
			break;	
	case 101: sValor += "5";
			alteraCelula(idCell,sValor);
			break;
	case 102: sValor += "6";
			alteraCelula(idCell,sValor);
			break;
	case 103: sValor += "7";
			alteraCelula(idCell,sValor);
			break;
	case 104: sValor += "8";
			alteraCelula(idCell,sValor);
			break;
	case 105: sValor += "9";
			alteraCelula(idCell,sValor);
			break;
	case 110: sValor += ".";
			alteraCelula(idCell,sValor);
			break;	
	case 190: sValor += ".";
			alteraCelula(idCell,sValor);
			break;	
	case 188: sValor += ",";
			alteraCelula(idCell,sValor);
			break;		
	case 109: sValor += "-";
			alteraCelula(idCell,sValor);
			break;	
	case 107: sValor += "+";
			alteraCelula(idCell,sValor);
			break;	
	case 106: sValor += "*";
			alteraCelula(idCell,sValor);
			break;	
	case 111: sValor += "/";
			alteraCelula(idCell,sValor);
			break;
	case 191: sValor += "/";
			alteraCelula(idCell,sValor);
			break;
	case 16: sValor += "";
			alteraCelula(idCell,sValor);
			break;
	/*case 46: sValor += "" + String.fromCharCode(tecla);
			alteraCelula(idCell,sValor);
			break;*/
	}
	if(sVal != sValor) bAlterado = true;

}

Oi pessoal!! Alguma dica depois que forneci o codigo?