Subtração currency
ola pessoal
tenho que fazer uma subtração de dois campos currency mas nunca funciona...
Queria subtrair o total2 - total, mas nao funciona aparece um monte de numeros sem logica....
fiz da seguinte forma:
var
Total2,Total,total3 Currency;
begin
table1.DisableControls;
try
while not table1.EOF do begin
Total := Total + table1.FieldByName(´subtotal´).AsCurrency;
Total2 := Total2 + table1.FieldByName(´Juros´).AsCurrency;
Table1.Next;
end;
finally
table1.EnableControls;
total3 := total - total2;
label5.Caption := FormatFloat(´#,0.00´, Total);
label3.Caption := FormatFloat(´,0.00´, Total2);
label10.Caption := FormatFloat(´,0.00´, Total3);
end;
alguem poderia me ajudar por favor...
agradeço a todos
tenho que fazer uma subtração de dois campos currency mas nunca funciona...
Queria subtrair o total2 - total, mas nao funciona aparece um monte de numeros sem logica....
fiz da seguinte forma:
var
Total2,Total,total3 Currency;
begin
table1.DisableControls;
try
while not table1.EOF do begin
Total := Total + table1.FieldByName(´subtotal´).AsCurrency;
Total2 := Total2 + table1.FieldByName(´Juros´).AsCurrency;
Table1.Next;
end;
finally
table1.EnableControls;
total3 := total - total2;
label5.Caption := FormatFloat(´#,0.00´, Total);
label3.Caption := FormatFloat(´,0.00´, Total2);
label10.Caption := FormatFloat(´,0.00´, Total3);
end;
alguem poderia me ajudar por favor...
agradeço a todos
Marcelo_vms
Curtidas 0
Respostas
Marco Salles
13/10/2004
talvez esta nao seje a melhor maneira de realizar isto..voce esta na verdade percorrendo registro por registro na sua base de dados e armazenando esses valores em duas variáveis que postriormente serão subtraidas..esta operação e custodiosa no item desempenho, apesar de voce sabiamente desabilitar os controles conscientes de dados conectados a tabela o que melhora em performace...Mas voltando no seu problema especifico, acredito que o que esta ocorrendo e que voce nao [b:5ad10534c6]inicializou os valores das variáveis total e total2[/b:5ad10534c6]....elas possivelmente conterrão Valores indesejavéis..tente isto
var Total2,Total,total3 Currency; begin table1.DisableControls; try total:=0; Total2:=0; while not table1.EOF do begin Total := Total + table1.FieldByName(´subtotal´).AsCurrency; Total2 := Total2 + table1.FieldByName(´Juros´).AsCurrency; Table1.Next; end; finally table1.EnableControls; total3 := total - total2; label5.Caption := FormatFloat(´#,0.00´, Total); label3.Caption := FormatFloat(´,0.00´, Total2); label10.Caption := FormatFloat(´,0.00´, Total3); end;
GOSTEI 0
Rômulo Barros
13/10/2004
Amigo, ´[b:9ad75e9994]acredito[/b:9ad75e9994]´ que o problema esteja na inicialização das variáveis. Quando variáves são locais, temos sempre q inicializá-las. Então, segue o Código:
:roll:
Var Total,Total2,Total3 : Currency; Begin Total := 0 ; Total2 := 0 ; Total3 := 0 ; ... ... End;
:roll:
GOSTEI 0
Marcelo_vms
13/10/2004
consegui....
ficou muito legal...
obrigado amigos...
ficou muito legal...
obrigado amigos...
GOSTEI 0