Author | Topic: Re: Round() function problems | |
---|---|---|
Andreas Gehrs-Pahl View the complete thread for this message in: | Re: Round() function problems on Wed, 19 Aug 2015 15:47:37 -0400 Carlos, >For example, Round( 0.3 * 1.65, 2 ) returned 0.50. Please take a look at my response in the thread: "Problem with round" in the "public.xbase++.bugreport" NewsGroup from June 27, 2015. Basically what you should do is a simple two-step rounding process. This will work for all numbers and all versions of Clipper and Xbase++. Just use the following replacement round function: Function RoundX(nValue, nDecimals, nPrecission) LOCAL nInitial := iif(empty(nPrecission), nDecimals + 1, nPrecission) return (Round(Round(nValue, nInitial), nDecimals)) And here is a sample program to show you how and why this works: Procedure Main() LOCAL nValue := 0.3 * 1.65 QOut(' 0.3 * 1.65 ==> ' + str( nValue , 22, 20)) QOut(' Round(0.3 * 1.65, 2) ==> ' + str( Round(nValue, 2) , 22, 20)) QOut('RoundX(0.3 * 1.65, 2) ==> ' + str(RoundX(nValue, 2) , 22, 20)) QOut('RoundX(0.3 * 1.65, 2, 2) ==> ' + str(RoundX(nValue, 2, 2), 22, 20)) QOut('RoundX(0.3 * 1.65, 2, 3) ==> ' + str(RoundX(nValue, 2, 3), 22, 20)) QOut('RoundX(0.3 * 1.65, 2, 4) ==> ' + str(RoundX(nValue, 2, 4), 22, 20)) QOut('RoundX(0.3 * 1.65, 2, 8) ==> ' + str(RoundX(nValue, 2, 8), 22, 20)) return Hope that helps, Andreas Andreas Gehrs-Pahl Absolute Software, LLC phone: (989) 723-9927 email: Andreas.GP@Charter.net web: http://www.Aerospace-History.net |