Fórum Parcelamento Exato #335481
01/01/2007
0
1ª Parcela: [b:919b8cbdfa]1,01[/b:919b8cbdfa]
2ª Parcela: [b:919b8cbdfa]1,00[/b:919b8cbdfa]
3ª Parcela: [b:919b8cbdfa]1,00[/b:919b8cbdfa]
4ª Parcela: [b:919b8cbdfa]1,00[/b:919b8cbdfa]
Alguem poderia me ajudar?
Rudá
Curtir tópico
+ 0Posts
02/01/2007
Aroldo Zanela
Fiz um pequeno exemplo para resolver o problema:
var ValorParcela: Currency; Saldo: Currency; I: SmallInt; begin ValorParcela := Trunc((edtValorTotal.Value / seParcelas.Value)*100)/100; Saldo := edtValorTotal.Value - (ValorParcela * seParcelas.Value); mmo1.Lines.Clear; for I := 1 to seParcelas.Value do begin if I = 1 then mmo1.Lines.Add(FormatFloat(´#,,0.00´, ValorParcela + Saldo)) else mmo1.Lines.Add(FormatFloat(´,,0.00´, ValorParcela)); end; end;
Gostei + 0
02/01/2007
Fortaum
var
curSaldo, curValorTotal, curValorParcela: Currency;
i, intParcelas: Integer;
begin
curSaldo:= 0;
curValorTotal:= 3.50;
intParcelas:= 3;
curValorParcela:= StrToFloat(FormatFloat(´0.00´, curValorTotal / intParcelas));
curSaldo:= curValorTotal - (curValorParcela * intParcelas);
Memo1.Lines.Clear;
for I := 1 to intParcelas do
begin
if I = 1 then
Memo1.Lines.Add(FormatFloat(´#,0.00´, curValorParcela + curSaldo))
else
Memo1.Lines.Add(FormatFloat(´,0.00´, curValorParcela));
end;
end;
Jader E. Gonçalves
Software Developer
Gostei + 0
02/01/2007
Aroldo Zanela
Estranho, acabei de testar R$ 3,50 e o resultado foi:
2x:
1,75
1,75
3x:
1,18
1,16
1,16
4x:
0,89
0,87
0,87
0,87
Gostei + 0
02/01/2007
Aroldo Zanela
Desculpem o ´flooder´, mas para testar, basta copiar o código abaixo e soltar sobre um novo FORMULÁRIO (não é sobre a Unit):
object btn1: TButton Left = 262 Top = 24 Width = 75 Height = 25 Caption = ´Processar´ TabOrder = 0 OnClick = btn1Click end object edtValorTotal: TRxCalcEdit Left = 12 Top = 26 Width = 121 Height = 21 AutoSize = False NumGlyphs = 2 TabOrder = 1 end object seParcelas: TSpinEdit Left = 137 Top = 25 Width = 121 Height = 22 MaxValue = 0 MinValue = 0 TabOrder = 2 Value = 0 end object mmo1: TMemo Left = 0 Top = 66 Width = 348 Height = 380 Align = alBottom Lines.Strings = ( ´mmo1´) TabOrder = 3 end object lbl1: TLabel Left = 12 Top = 14 Width = 51 Height = 13 Caption = ´Valor Total´ end object lbl2: TLabel Left = 138 Top = 14 Width = 41 Height = 13 Caption = ´Parcelas´ end
É necessário ter a RxLib instalada ou fazer algumas alterações para compatibilizar o código.
Gostei + 0
02/01/2007
Rudá
[b:7cc410270d]1.02
1.00
1.00
1.00[/b:7cc410270d]
Não poderia ficar assim:
[b:7cc410270d]1.01
1.01
1.00
1.00[/b:7cc410270d]
Pq é o valor mais aproximado!
Pq isso é para fazer o mesmo processo do cartão de crédito que divide bem aproximado!
Gostei + 0
02/01/2007
Aroldo Zanela
Tenho que fazer mais alguns testes, mas me parece que esse aqui fica do jeito que você quer:
var ValorParcela, Saldo, Residuo: Currency; I: SmallInt; begin ValorParcela := Trunc((edtValorTotal.Value / seParcelas.Value)*100)/100; Saldo := edtValorTotal.Value - (ValorParcela * seParcelas.Value); Residuo := 0.01; mmo1.Lines.Clear; for I := 1 to seParcelas.Value do begin if Saldo>0 then Saldo := Saldo - Residuo else Residuo := 0; mmo1.Lines.Add(FormatFloat(´#,,0.00´, ValorParcela + Residuo)); end; end;
Gostei + 0
02/01/2007
Rudá
[b:7d905c9119]1,01
1,01
1,00
1,00[/b:7d905c9119]
mas se colocar 4,03 ai ele fica errado olhe como ficou
[b:7d905c9119]1,01
1,01
1,01
1,01[/b:7d905c9119]
Gostei + 0
02/01/2007
Aroldo Zanela
Acabei de testar e ficou assim:
1,01 1,01 1,01 1,00
Gostei + 0
02/01/2007
Rudá
Qual a diferença de Currency para Extended?
Gostei + 0
02/01/2007
Emerson Nascimento
var ValorParcela, UltimaParcela: Currency; I: SmallInt; begin ValorParcela := Round((edtValorTotal.Value / seParcelas.Value)*100)/100; UltimaParcela := edtValorTotal.Value - (ValorParcela * (seParcelas.Value - 1)); mmo1.Lines.Clear; for I := 1 to seParcelas.Value do begin if i = seParcelas.Value then ValorParcela := UltimaParcela; mmo1.Lines.Add(FormatFloat(´#,,0.00´, ValorParcela)); end; end;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)