Click here to Skip to main content
15,887,135 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Milliseconds to Minutes Pin
Dave Kreskowiak10-May-07 6:33
mveDave Kreskowiak10-May-07 6:33 
GeneralRe: Milliseconds to Minutes Pin
Stigmurder10-May-07 7:19
Stigmurder10-May-07 7:19 
JokeRe: Milliseconds to Minutes Pin
CPallini10-May-07 9:03
mveCPallini10-May-07 9:03 
GeneralRe: Milliseconds to Minutes Pin
Dave Kreskowiak10-May-07 10:42
mveDave Kreskowiak10-May-07 10:42 
QuestionVB6 Int() Function Pin
Marcus J. Smith10-May-07 5:05
professionalMarcus J. Smith10-May-07 5:05 
AnswerRe: VB6 Int() Function Pin
Dave Kreskowiak10-May-07 5:17
mveDave Kreskowiak10-May-07 5:17 
GeneralRe: VB6 Int() Function [modified] Pin
Marcus J. Smith10-May-07 5:26
professionalMarcus J. Smith10-May-07 5:26 
GeneralRe: VB6 Int() Function Pin
Dave Kreskowiak10-May-07 6:28
mveDave Kreskowiak10-May-07 6:28 
CleaKO wrote:
It would appear that it always rounds to the number lower not closer to zero so -8.12 goes to -9 whereas 20.8 goes to 20. That seems like a bug to me.


Not quite. OK. I didn't notice this before, but the Int function is NOT the same as CInt.

In VB6, if you do this:
CInt(Csng("-8.62") + 0.5)
you get -8.

If you do this:
Int(Csng("-8.62") + 0.5)
you get -9.

Why? The answer is in the documentation:
Int, Fix Functions[^]
Both Int and Fix remove the fractional part of a number and return the resulting integer value.

The difference between Int and Fix is that if the number is negative, Int returns the first negative integer less than or equal to that number, whereas Fix returns the first negative integer greater than or equal to that number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.


Cint()[^]
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.

Under VB.NET, the CInt and Convert.ToInt32() methods follow the old VB6 CInt function. You can still use the original VB6 code VB.NET, the Int function IS still there.


A guide to posting questions on CodeProject[^]

Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


GeneralRe: VB6 Int() Function Pin
Marcus J. Smith10-May-07 6:38
professionalMarcus J. Smith10-May-07 6:38 
AnswerRe: VB6 Int() Function Pin
Guffa10-May-07 8:18
Guffa10-May-07 8:18 
GeneralRe: VB6 Int() Function Pin
Marcus J. Smith10-May-07 8:28
professionalMarcus J. Smith10-May-07 8:28 
QuestionCaesar Cipher Crack Pin
Irshadt10-May-07 3:27
Irshadt10-May-07 3:27 
AnswerRe: Caesar Cipher Crack Pin
Colin Angus Mackay10-May-07 3:29
Colin Angus Mackay10-May-07 3:29 
QuestionCaesar Cipher Crack Pin
Irshadt10-May-07 3:24
Irshadt10-May-07 3:24 
AnswerRe: Caesar Cipher Crack Pin
Colin Angus Mackay10-May-07 3:30
Colin Angus Mackay10-May-07 3:30 
GeneralRe: Caesar Cipher Crack Pin
Christian Graus10-May-07 10:29
protectorChristian Graus10-May-07 10:29 
QuestionRe: Regular Expression Pin
ant1xxx10-May-07 1:55
ant1xxx10-May-07 1:55 
AnswerRe: Regular Expression Pin
Christian Graus10-May-07 2:14
protectorChristian Graus10-May-07 2:14 
QuestionPassing custom object to web service Pin
BobsAfro10-May-07 1:15
BobsAfro10-May-07 1:15 
AnswerRe: Passing custom object to web service Pin
nlarson1110-May-07 4:05
nlarson1110-May-07 4:05 
GeneralRe: Passing custom object to web service Pin
BobsAfro10-May-07 5:42
BobsAfro10-May-07 5:42 
GeneralRe: Passing custom object to web service Pin
nlarson1110-May-07 5:48
nlarson1110-May-07 5:48 
GeneralRe: Passing custom object to web service Pin
nlarson1110-May-07 5:52
nlarson1110-May-07 5:52 
GeneralRe: Passing custom object to web service Pin
BobsAfro10-May-07 5:54
BobsAfro10-May-07 5:54 
GeneralRe: Passing custom object to web service Pin
nlarson1110-May-07 5:59
nlarson1110-May-07 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.