On Jul 27, 2006, at 1:32 PM, [EMAIL PROTECTED] wrote:
dim d as double
dim i as integer
d = 72.0 / 2000.0
d = d * 750.0
i = d
MsgBox str(d)
msgbox str(i)
Why does this code produce a 26 for the second message box
instead of a
27? How can I make RB produce a 27 like every other language/
calculator
that I tried?
Are you sure about the "every other language" portion of your
statement? In my experience it is normal for the fractional portion
of a double or single to be thrown away when assigning to an integer
property. To compensate for this use the statement:
i = d + 0.50000001
and you will get the 27 for i instead of the 26.
Do not just use
i = d + 0.5
since I do not believe that 0.5 can be represented exactly in a
double it will be something like 0.4999999999. By throwing in the
extra 1 way out there you are making sure that you get the desired
rounding.
There is also a ROUND function, but I have not used it and therefore
cannot vouch for it.
i = Round(d)
=== A Mac addict in Tennessee ===
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>