Rounding up to next highest $25 increment

G

GaryS

Hi,

Need a little help with rounding up. In A2K I have a form with a textbox
that displays a security deposit. Security deposit is calculated by rounding
the payment to the next $25 increment, hence a payment of 324.53 should have
a security deposity of $325.00, but a payment of $325.01 should have a
security deposit of $350.00. The code I am using for a datasource for
txtSecurity deposit usually works correctly, but for this payment ($324.53)
it rounds to $350.00. Here is the code..

=(([txtPayment]\25)*25+[txtSecDepRndTo])

txtSecDepRndTo holds the $25 incremental value.

Incidentally, if the payment is $324.49 my code rounds the Security Deposit
to $325.00 as it should.

Any help would be greatly appreciated.
 
J

John Welch

Gary, when you use integer division (the \ operator), it first rounds all
the values being divided to integers. Therefore, your 324.53 is getting
rounded to 325 before the division happens. You can chop off the decimal
part before dividing to prevent this from happening by using the int
function:
=((int([txtPayment]\25))*25 ...

-John
 
M

Marshall Barton

GaryS said:
Need a little help with rounding up. In A2K I have a form with a textbox
that displays a security deposit. Security deposit is calculated by rounding
the payment to the next $25 increment, hence a payment of 324.53 should have
a security deposity of $325.00, but a payment of $325.01 should have a
security deposit of $350.00. The code I am using for a datasource for
txtSecurity deposit usually works correctly, but for this payment ($324.53)
it rounds to $350.00. Here is the code..

=(([txtPayment]\25)*25+[txtSecDepRndTo])

txtSecDepRndTo holds the $25 incremental value.

Incidentally, if the payment is $324.49 my code rounds the Security Deposit
to $325.00 as it should.


Try this:
=Fix((txtPayment + txtSecDepRndTo - .01) / txtSecDepRndTo) *
txtSecDepRndTo
 
G

GaryS

Marsh,
txtSecDepRndTo<<

This did the trick for me. Thanks everybody for your wonderful help.
--
Gary in Michigan, USA


Marshall Barton said:
GaryS said:
Need a little help with rounding up. In A2K I have a form with a textbox
that displays a security deposit. Security deposit is calculated by rounding
the payment to the next $25 increment, hence a payment of 324.53 should have
a security deposity of $325.00, but a payment of $325.01 should have a
security deposit of $350.00. The code I am using for a datasource for
txtSecurity deposit usually works correctly, but for this payment ($324.53)
it rounds to $350.00. Here is the code..

=(([txtPayment]\25)*25+[txtSecDepRndTo])

txtSecDepRndTo holds the $25 incremental value.

Incidentally, if the payment is $324.49 my code rounds the Security Deposit
to $325.00 as it should.


Try this:
=Fix((txtPayment + txtSecDepRndTo - .01) / txtSecDepRndTo) *
txtSecDepRndTo
 
Top