Theotokos Posted June 13, 2013 Report Share Posted June 13, 2013 Pessoal, desculpa essa ai mais deu um branco total... Como faço para truncar um valor ao invés de arrendondar? Exemplo: Valor Original Valor Truncado Valor Arrendondado R$ 19,546 R$ 19,54 R$ 19,55 Quote Link to comment Share on other sites More sharing options...
Luiz Fernando Posted June 13, 2013 Report Share Posted June 13, 2013 ola Rone, veja a sintaxe abaixo round(seu valor,casa decimais) Luiz Fernando Quote Link to comment Share on other sites More sharing options...
Theotokos Posted June 13, 2013 Author Report Share Posted June 13, 2013 ola Rone, veja a sintaxe abaixo round(seu valor,casa decimais) Luiz Fernando Sim! mas o Round ele arrendonda o valor... Eu já uso assim!!!! E que preciso é truncar o valor. Quote Link to comment Share on other sites More sharing options...
Luiz Fernando Posted June 13, 2013 Report Share Posted June 13, 2013 mania de ler rapido, veja se te ajuda... #define Trunca_valor(vl,dec) VAL(LEFT(STR(vl,15+dec+8,dec+8),15+dec)) nvalor:=Trunca_valor(nvalor,2) Abraços Luiz Fernando Quote Link to comment Share on other sites More sharing options...
Theotokos Posted June 13, 2013 Author Report Share Posted June 13, 2013 mania de ler rapido, veja se te ajuda... #define Trunca_valor(vl,dec) VAL(LEFT(STR(vl,15+dec+8,dec+8),15+dec)) nvalor:=Trunca_valor(nvalor,2) Abraços Luiz Fernando Vlw! vou testar.... Theotokos 1 Quote Link to comment Share on other sites More sharing options...
Theotokos Posted June 13, 2013 Author Report Share Posted June 13, 2013 Valeu Luiz Fernando... Deu Certo!!! Quote Link to comment Share on other sites More sharing options...
SAOliveira Posted June 13, 2013 Report Share Posted June 13, 2013 Só mais uma forma, apesar de ser da época com clipper DOS. FUNCTION PCS_Trunca(valor,decimal)LOCAL nVal:=Val(Str(Int(Valor))+"."+Subs(AllTrim(Str(Valor-Int(valor))),3,decimal))RETURN(nVal) Theotokos 1 Quote Link to comment Share on other sites More sharing options...
emotta Posted June 13, 2013 Report Share Posted June 13, 2013 nValor := nValor - 0.005 nValor := Round(nValor,2) Pessoal, desculpa essa ai mais deu um branco total... Como faço para truncar um valor ao invés de arrendondar? Exemplo: Valor Original Valor Truncado Valor Arrendondado R$ 19,546 R$ 19,54 R$ 19,55 Quote Link to comment Share on other sites More sharing options...
cendon Posted June 13, 2013 Report Share Posted June 13, 2013 SET FIXED OFF Para de arredondar SET FIXED ON Volta a arredondar, segundo o parâmetro SET DECIMALS [NUMERO DE CASAS DECIMAIS] o valor default do SET DECIMALS é 2 Quote Link to comment Share on other sites More sharing options...
microfly Posted June 14, 2013 Report Share Posted June 14, 2013 Function Trunca( nnum, ndec)/*************************************************************************** Corta as casas decimais excedentes de um n£mero (nnum) deixando somente a quantidade determinada por "ndec". - nnum: N£mero a ser "truncado". - ndec: Quantidade de casas decimais desejadas.****************************************************************************/ Local cnum:='', nret:=0, cpict:='999999999999999.' cpict += Replicate( '9', (ndec+1)) // Ajusta a Picture a ser usada cnum := Transform( nnum, cpict) // Transforma o n£mero em "texto". cnum := Alltrim( cnum) // Elimina "brancos". cnum := Left( cnum, Len(cnum)-1) // Pega o texto, sem a última casa. nret := Val( cnum) // Transforma o texto em n§ novamente Return(nret)/**************************************************************************/ use assim Nota1->Valoricm:= Trunca((Nota1->Valortot*nIcmcli)/100,2) Nota1->Vltcomis:= Trunca((Nota1->Valortot*nComis)/100,2) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.