Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Seems like a bug to me
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01061738
Message ID:
01061744
Views:
17
This message has been marked as a message which has helped to the initial question of the thread.
Hi Geoff,

>Why then does
>
>
?INT(?m.nMins)
>
>
>output 3929

Because the calculated difference is not 3930, rather 3929.999999776483. Rounding this value as the ?-command does results in 3930, whereas the integer part is clearly 3929:
? (dt_b - dt_a)/60*1000000000000
How comes there's a difference? Floating point values are binary fractional values, something like 110011001.1100110. We developers, however, deal with values that are converted from this actual value into a decimal representation. The decimal value is an approximation of the actual value, not vice versa.

In your case, you are providing two datetime values and assume that the difference is an integer value. However, we don't know how this difference is calculated. VFP might convert the value into a Windows DATETIME value starting in 1/1/1600 with a precision of 10 nanoseconds generating a huge value, or, VFP might use a lot of divisions on an integer value, or what I assume, VFP converts the datetime value into a floating point number where the whole part is a julian date and the fraction is the time in seconds divided by 86400. In any case, the actual process requires floating point operations at some point which results in approximal values when converted back to decimal.

Usually VFP does a pretty good job of hiding this complexity. However, if you explicitely cast a floating point into an integer, it won't stop you. You should know what you want to do then. <s> If you want to remove an potential fractions, ROUND(value,0) does a better job on floating point values than INT(). INT() doesn't take away the fraction from the visible, rounded decimal approximation, it converts the actual binary value into an integer.
--
Christof
Previous
Reply
Map
View

Click here to load this message in the networking platform