485
edits
(→Source) |
m (typo) |
||
(7 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
= Rounding Numbers = | |||
'' The following has been taken from the DAW newsgroup, User Contributed Oct 6 2000 '' | '' The following has been taken from the DAW newsgroup, User Contributed Oct 6 2000 '' | ||
== MARF - A Mutually Agreed Rounding Function?! == | |||
Aside from UI issues, OS and hardware problems, perhaps one of the most | Aside from UI issues, OS and hardware problems, perhaps one of the most | ||
Line 25: | Line 25: | ||
ie. ± 99,999,999,999,999.99999999. | ie. ± 99,999,999,999,999.99999999. | ||
(b) Rounding should occur when the digit to the right of the rounding | (b) Rounding '''up''' should occur when the digit to the right of the rounding | ||
position is 5 or above. I take this to be a reasonably 'international' | position is 5 or above, otherwise rounding '''down''' should occur. I take this to be a reasonably 'international' | ||
convention. | convention. | ||
Line 57: | Line 57: | ||
Michael Pilsworth | Michael Pilsworth | ||
= Source = | |||
<source lang="dataflex"> | |||
// =========================================================================== | // =========================================================================== | ||
// | // | ||
Line 105: | Line 105: | ||
// | // | ||
// =========================================================================== | // =========================================================================== | ||
Function Round_Number GLOBAL number nVal integer iRnd returns Number | Function Round_Number GLOBAL number nVal integer iRnd returns Number | ||
// If the rounding precision falls in the range -5 to +8, then return:- | // If the rounding precision falls in the range -5 to +8, then return:- | ||
Line 112: | Line 112: | ||
(Number(Abs(nVal) / nVal) * 0.5 / (Number(10 ^ (iRnd min 8))) + nVal ; | (Number(Abs(nVal) / nVal) * 0.5 / (Number(10 ^ (iRnd min 8))) + nVal ; | ||
/ (Number(10 ^ (8 - (iRnd min 8)))) * (Number(10 ^ (8 - (iRnd min 8))))) | / (Number(10 ^ (8 - (iRnd min 8)))) * (Number(10 ^ (8 - (iRnd min 8))))) | ||
/ / Else, where the rounding precision is in the range -6 to -13, return:- | // Else, where the rounding precision is in the range -6 to -13, return:- | ||
Function_Return ; | Function_Return ; | ||
(Number(Abs(nVal) / nVal) * 0.5 * (Number(10 ^ (Abs(iRnd) min 13))) ; | (Number(Abs(nVal) / nVal) * 0.5 * (Number(10 ^ (Abs(iRnd) min 13))) ; | ||
Line 118: | Line 118: | ||
* (Number(10 ^ 13)) * (Number(10 ^ ((Abs(iRnd) - 5) min 8)))) | * (Number(10 ^ 13)) * (Number(10 ^ ((Abs(iRnd) - 5) min 8)))) | ||
End_Function | End_Function | ||
</source> | |||
= Links = | |||
* https://support.dataaccess.com/Forums/showthread.php?55971-Rounding-to-nearest-5-cents | |||
[[Category: Basics]] |