#141728 - 2005-06-15 08:18 PM
Re: Feeling really stupid
|
Gargoyle
MM club member
   
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
So my problem is that I want it return .8 So I should use ?? instead
I tried doing it without the CINT and I get an error in expression.
And I do realize now why it was returning a 0, but still am not sure how to convert the string to a number
Edited by Gargoyle (2005-06-15 08:22 PM)
|
|
Top
|
|
|
|
#141731 - 2005-06-15 08:50 PM
Re: Feeling really stupid
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Try this: Code:
'1 + 1.5 = ' 1 + 1.5 ? '"1" + 1.5 = ' "1" + 1.5 ? '1.0 + 1.5 = ' 1.0 + 1.5 ?
Once you understand this, truly you will be enlightened
|
|
Top
|
|
|
|
#141735 - 2005-06-16 10:05 AM
Re: Feeling really stupid
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Read the manual section on CInt() - this gives a reasonable explanation of what's going on. I'll highlight the most important points:
- Values are rounded to the nearest even number when the fractional part is exactly 0.5
- If you are after the integer part rather than the nearest integer, use Int() which does not round the value but simply drops the fractional part.
|
|
Top
|
|
|
|
#141737 - 2005-06-16 05:31 PM
Re: Feeling really stupid
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I've just downloaded 4.22 to check, and the remarks for CInt() read as follows:
Quote:
Remarks CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
I use an older printed version (4.20) and the remarks are the same.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 918 anonymous users online.
|
|
|