views:

133

answers:

2

I have an Informix-SQL based Pawnshop app which calculates an estimate of how much money should be loaned to a customer, based on the weight and purity of gold. The minimum the pawnshop lends is $5.00. The pawnshop employee will typically lend amounts which either ends with a 5 or 0. examples: 10, 15, 20, 100, 110, 125, etc. They do this so as to not run into shortage problems with $1.00 bills. So, if for example my system calculates the loan should be: $12.49, then round it to $10, $12.50 to $15.00, $13.00 to $15.00, $17.50 to $20.00, and so on!..The employee can always override the rounded amount if necessary. Is it possible to accomplish this within the instructions section of a perform screen or would I have to write a cfunc and call it from within perform?.. Are there any C library functions which perform interval rounding of money values?.. On another note, I think the U.S. Government should discontinue the use of pennies so that businesses can round amounts to the nearest nickel, it would save so much time and weight in our pockets!

+6  A: 

I'd just divide by 5, round to the appropriate integer, and multiply by 5.

There might be an easier way but that would work.

John at CashCommons
+2  A: 

The C function round and relatives would do what you ask.

float in_fives = roundf( exact_change / 5. ) * 5.;

There is also rint, which you might avoid because it is not guaranteed to round $12.50 properly.

Potatoswatter