I am trying to figure out payments for restitution and a final payment amount and am having problems mixing doubles and integers.
Say a person is ordered to pay $264.53 making a $50 payment. I need to be able to calculate 5 payments of $50 and a final payment of 14.53.
I have a function that takes the total amount due and the payment amount (there are some other parameters, but they aren't neccessary for this part of the function). I want to be able to come up with an integer for the 5 payments, but it's not working correctly. Here's what I've got:
The final result is a sentence inserted into an agreement like:
I agree to pay $264.53 to VictimName, making 5 payments of $50 and a final payment of $14.53 beginning 10/27/2001 and every week thereafter.
Currently, I am getting:
I agree to pay $264.53 to VictimName, making 5.2906 payments of $50 beginning 10/27/2001 and every week thereafter.
can someone help me get this?
thanks!
leslie
Say a person is ordered to pay $264.53 making a $50 payment. I need to be able to calculate 5 payments of $50 and a final payment of 14.53.
I have a function that takes the total amount due and the payment amount (there are some other parameters, but they aren't neccessary for this part of the function). I want to be able to come up with an integer for the 5 payments, but it's not working correctly. Here's what I've got:
Code:
function PaymentDetailsText(VicName : string; BeginDate : String; PayDay : string; Payment : double; TotalAmt : double; Frequency : integer): string;
var
NumOfPayments : double;
LastPayAmount : double;
begin
if (Payment > 0) and (TotalAmt > 0) then
begin
NumOfPayments := TotalAmt / Payment;
lastPayAmount := TotalAmt - (Payment * NumOfPayments);
end
else
NumOfPayments := 1;
result := 'I agree to pay $' + FloatToStr(TotalAmt) + ' to ' + VicName + ', making ' + FloatToSTr(NumOfpayments);
if NumOfPayments > 1 then
begin
result := result + ' payments of $' + FloatToSTr(Payment);
if lastPayAmount > 0 then
result := result + ' and a final payment of $' + FloatToSTr(lastPayAmount);
end
else
result := result + ' payment of $' + FloatToSTr(TotalAmt);
result := result + ' beginning ' + ConvertAS400Date(BeginDate) + ' and';
Case Frequency of
1 : result := result + ' monthly on the ' + PayDay + ' thereafter.';
2 : result := result + ' every two weeks thereafter.';
3 : result := result + ' every week thereafter.';
end;
end;
The final result is a sentence inserted into an agreement like:
I agree to pay $264.53 to VictimName, making 5 payments of $50 and a final payment of $14.53 beginning 10/27/2001 and every week thereafter.
Currently, I am getting:
I agree to pay $264.53 to VictimName, making 5.2906 payments of $50 beginning 10/27/2001 and every week thereafter.
can someone help me get this?
thanks!
leslie