!**********************************************************************
!* *
!* MODULE: TDINCR.SQC *
!* AUTHOR: TONY DELIA. *
!* DATE: 02/02/1999. *
!* SYSTEM: TD SQR UTILITY SERIES. *
!* DESC: INCREMENTAL ROUNDING ROUTINE. *
!* *
!**********************************************************************
!* *
!* PASS: $I_method => Rounding Method (U, D, R) *
!* #I_incr => Incremental Value *
!* #I_amount => Input Amount *
!* *
!* RETURNS: #O_amount => Output Amount (Rounded) *
!* *
!**********************************************************************
!* *
!* USAGE: let #I_amount = 1234.68 *
!* *
!* 1) let #I_incr = .25 *
!* do Round-Incr('U', #I_incr, #I_amount, #O_amount) *
!* *
!* 2) let #I_incr = .25 *
!* do Round-Incr('D', #I_incr, #I_amount, #O_amount) *
!* *
!* 3) let #I_incr = .25 *
!* do Round-Incr('R', #I_incr, #I_amount, #O_amount) *
!* . *
!* 4) let #I_incr = 1 *
!* do Round-Incr('U', #I_incr, #I_amount, #O_amount) *
!* . *
!* 5) let #I_incr = 100 *
!* do Round-Incr('U', #I_incr, #I_amount, #O_amount) *
!* . *
!* 6) let #I_incr = 150 *
!* do Round-Incr('U', #I_incr, #I_amount, #O_amount) *
!* . *
!* 7) let #I_incr = 300 *
!* do Round-Incr('U', #I_incr, #I_amount, #O_amount) *
!* . *
!* 8) let #I_incr = 500 *
!* do Round-Incr('U', #I_incr, #I_amount, #O_amount) *
!* . *
!* 9) let #I_incr = 650 *
!* do Round-Incr('U', #I_incr, #I_amount, #O_amount) *
!* . *
!* . *
!* #Include 'tdincr.sqc' *
!* *
!**********************************************************************
!* *
!* RESULTS: Input rounded to Incremental Value based on Round *
!* Method. *
!* *
!* INPUT Round OUTPUT *
!* Example Amount Method Increment Amount *
!* ------- -------- ------ ---------- ------- *
!* 1 1234.68 UP .25 1234.75 *
!* 2 1234.68 DOWN .25 1234.50 *
!* 3 1234.68 ROUND .25 1234.75 *
!* 4 1234.68 UP 1.00 1235.00 *
!* 5 1234.68 UP 100.00 1300.00 *
!* 6 1234.68 UP 150.00 1350.00 *
!* 7 1234.68 UP 300.00 1500.00 *
!* 8 1234.68 UP 500.00 1500.00 *
!* 9 1234.68 UP 650.00 1300.00 *
!* ------- -------- ------ ---------- ------- *
!* *
!**********************************************************************
!* *
!* LEGAL: CONFIDENTIALITY INFORMATION. *
!* *
!* This module is the original work of Tony DeLia. It *
!* can be considered ShareWare under the following *
!* conditions. *
!* *
!* A - The author's name (Tony DeLia) remains on any *
!* and all versions of this module. *
!* B - Any modifications must be clearly identified. *
!* C - A "vanilla" copy of this module must be kept *
!* alongside any revised versions. *
!* *
!**********************************************************************
!* *
!* WEBSITE: http://www.sqrtools.com *
!* *
!* Questions/Comments: tdelia@erols.com *
!* *
!**********************************************************************
!* REVISIONS: *
!**********************************************************************
!* *
!* DATE PROGRAMMER DESCRIPTION *
!* ---------- --------------- --------------------------------------- *
!* *
!* 02/02/1999 DELIA,TONY ORIGINAL CODING. *
!* *
!* 09/14/1999 DELIA,TONY ADDED ROUNDING METHOD AS 1ST PARAMETER. *
!* *
!* U = ROUND UP TO INCREMENT *
!* D = ROUND DOWN TO INCREMENT *
!* R = ROUND TO NEAREST INCREMENT *
!* [DEFAULT ROUNDING METHOD] *
!* *
!**********************************************************************
!**********************************************************************
!* Round Increment *
!**********************************************************************
begin-procedure Round-Incr($I_method, #I_incr, #I_amount, :#O_amount)
evaluate $I_method
when = 'U'
let #O_amount = #I_incr * ceil(#I_amount / #I_incr)
when = 'D'
let #O_amount = #I_incr * floor(#I_amount / #I_incr)
when-other
let #O_amount = #I_incr * floor((#I_amount + #I_incr/2) / #I_incr)
end-evaluate
end-procedure
!**********************************************************************
|