Cint(String) Not equal Cint(double)

Please report bugs

Cint(String) Not equal Cint(double)

Postby pappawinni » Thu Aug 19, 2010 11:01 am

Just tested if I could use Cint() instead of val() to convert a string to integer and
found that e.g.
CInt(-123.123) delivers -123
while
CInt( "-123.123" ) delivers -122
strange, isn't it ?

Same results with CLng
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Cint(String) Not equal Cint(double)

Postby Slowdown » Thu Aug 19, 2010 6:51 pm

To make it more mysterious try,

Cint(val("-123.123")) > result -123 :)
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Cint(String) Not equal Cint(double)

Postby pappawinni » Sat Aug 21, 2010 7:14 am

Hi Slowdown,

strangely in VBA - even if I got the impression that this is very type tolerant - Cint does not accept string as input.
So you would need to code CInt(Val(string)).

But I think as CInt acceptes String in KBasic it should deliver correct results.
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Cint(String) Not equal Cint(double)

Postby Slowdown » Sat Aug 21, 2010 9:10 am

Hi pappawinni,
I agree with you, if accepted return the correct value or set an error if it not accept a string.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Cint(String) Not equal Cint(double)

Postby tseyfarth » Sat Aug 21, 2010 11:14 pm

VB6 did/does accept Cint("123").

I found that I had to change this practice for KB.

Either way is fine, so long as we know what to use, and the results are correct.

Tim
tseyfarth
 
Posts: 101
Joined: Mon Aug 02, 2010 10:11 am

Re: Cint(String) Not equal Cint(double)

Postby pappawinni » Sun Aug 22, 2010 9:47 pm

Hi Tim,

You - in one case - used int(string) instead of CInt(string) and this is a different story
I told you to use val(string).. because..
Cint() cuts the decimals .. and in Kbasic it accepts string, but for negative values, delivers wrong result.
int() rounds to the next lower Integer... which makes a difference especially for negative values.
Cint(-123.123) delivers -123 while
int(-123.123) delivers -124 ! int() in KBasic does not accept string as input
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany


Return to Bug-Reports

cron