Subject Re: Problem with int() function
From Ken Mayer <>
Date Fri, 17 Mar 2017 09:03:20 -0700
Newsgroups dbase.getting-started

On 3/17/2017 7:50 AM, Larry Winkler wrote:
> OK.  I'm a pain in the butt.  Here is a little test program to prove my point.  If the Integer function was working properly, there would be nothing to print.
> I finally had to disable all the code I had checking the user's input because of this problem.  It seems to me that there is a bug in dBase causing the issue.
> Thanks for your patience.

Have you looked in the dUFLP:

for example, is designed to deal with really large numbers.

Also, in the dUFLP, in the file MiscCode.prg:

      Author...: Ken Chan, updated by Rich Muller to test for an empty
                 value ...
      Date.....: November 23, 2004
      Notes....: This helps deal with the 'rounding error' issues
                 in dBASE. Note that while this is not *really*
                 a bug in dBASE, and more of an issue with the
                 underlying C++ code that dBASE is written in,
                 it can be annoying, and the round() function
                 built into dBASE often returns results that are
                 not truly desirable.

                 Ken Chan notes: "I seem to recall some cases which still
                 do not behave as expected. It should be noted that
                 it (this function) relies on SET PRECISION -- which --
                 as always, should be as low as possible, but not lower
                 than nPlace (although given the minimum PRECISION
                 of 10, that's usually not a problem)."
     Usage.....: roundPrec( <nArg>, <nPlace> )
     Parameters: nArg   = numeric value to round
                 nPlace = decimal places to round off at
     Returns...: numeric -- 0 if empty parameter ...
function roundPrec( nArg, nPlace )
    if nPlace <= 0 or nArg == 0
       return round( nArg, nPlace )
    if empty(nArg)
       return 0.00
    local nAdj
    if (int( nArg * 10^nPlace ) + iif( nArg > 0, 0.5, -0.5 )) ;
       / 10^nPlace == nArg
       nReturn = round( nArg + sign( nArg )/10^(nPlace+1), nPlace )
       nReturn = round( nArg, nPlace )
return nReturn
// end of function: roundPrec()

And in The dBASE Book Plus, Chapter 14, there is a discussion of the new
number Object, as well as SET HIGHPRECISION ... all things you might
want to look at.


*Ken Mayer*
Ken's dBASE Page:
The dUFLP:
dBASE Books: