Rounding Numbers: Difference between revisions

m
typo
No edit summary
m (typo)
 
(5 intermediate revisions by 4 users not shown)
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


[[Image:ROUNDNUM.zip| Download Roundnum.fnc (zipfile)]]
hold on ... there's an upload restriction preventing this... will upload it later...
uploading of .zip files are disabled for now (see [[Should We Have ZipFiles]] ) --[[User:Jka|Jka]] 09:50, 30 September 2007 (CEST)




= Source =
= Source =
<source lang="dataflex">
  // ===========================================================================
  // ===========================================================================
  //
  //
Line 108: 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 115: 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 121: 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


= Links =
[[Category: Basics]]
* http://www.redeemedsoftware.com/normal.asp?pageid=113