************************************************************ * Procedure...: DecRound * Parameters..: tnVal, tnTrimVal, tlFullVal * tnVal is given value * tnTrimVal is 'set decimal' value to round to * tlFullVal is a logical. .T. means use the full * number for rounding, otherwise, just use * the decimal portion * * Author......: Alan Popow * Created.....: September 10, 2002 * * Purpose.....: Round to the nearest tnTrimVal multiple * ie - DecTrim(5.44, .25) will round 5.44 to * nearest .25 - this will return 5.50 * decround(7.637, .222, .T.) will return 7.548, * because 7.767 is closer to 7.548 than to * 7.770, but * decround(7.637, .222) will return 7.666 * because .637 is closer to .666 than to * .444 *if anyone understands what I just said, I'd * appreciate an explanation. * Called by...: Vrs * * Returns.....: lnRetult - Rounded Value * * Notes.......: ************************************************************ Function DecRound(tnVal, tnTrimVal, tlFullVal) LOCAL lnResult, lnLow, lnHi, lnSaveInt IF PCOUNT() < 3 tlFullVal = .F. ENDIF * save and dump integer portion if not using full value IF !tlFullVal lnSaveInt = INT(tnVal) tnVal = tnVal - lnSaveInt ENDIF * find value next lowest to tnVal lnLow = tnTrimval * (INT(tnVal/tnTrimVal)) * find next higher value lnHi = lnLow + tnTrimVal * compare lower and higher values to tnval lnResult = IIF((lnHi - tnVal) > (tnVal - lnLow), lnLow, lnHi) IF !tlFullVal lnResult = lnResult + lnSaveInt ENDIF RETURN lnResultYou'll need to build in some error checking, but as far as I can tell, this works.