VB6 Round returning wrong results

JavaMomma

Senior member
Oct 19, 2000
701
0
71
?round(0.5)
0
?round(0.51)
1
?round(1.5)
2
?round(2.5)
2
?round(2.51)
3

I dont know about those results...seems wrong to me.

This must be the new msMath.
 

Haircut

Platinum Member
Apr 23, 2000
2,248
0
0
CInt (number) behaves in the same way.

Apparently it rounds to the nearest even number (presumably it counts 0 as even)

It seems to work in a similar way when rounding to n-decimal places

?round(1.45,1) gives 1.4
?round(1.55,1) gives 1.6

You could always write your own function that works properly.
 

Confused

Elite Member
Nov 13, 2000
14,166
0
0
Yeah, Round in VB basically chops off everything after the .


Confused
 

Burnsy

Member
Dec 30, 2001
90
0
0
Round rounds to nearest specified number of decimal places. There's a second optional argument to specify the number of decimal places.

More detail here
 

JavaMomma

Senior member
Oct 19, 2000
701
0
71
Originally posted by: Burnsy
Round rounds to nearest specified number of decimal places. There's a second optional argument to specify the number of decimal places.

More detail here

Debug.Print Round(0.5, 0)
Debug.Print Round(1.5, 0)

Output:
0
2
 

JavaMomma

Senior member
Oct 19, 2000
701
0
71
Originally posted by: Haircut
CInt (number) behaves in the same way.

Apparently it rounds to the nearest even number (presumably it counts 0 as even)

It seems to work in a similar way when rounding to n-decimal places

?round(1.45,1) gives 1.4
?round(1.55,1) gives 1.6

You could always write your own function that works properly.

Yeah I thats what I did, very simple to write a round function. I was just wondering why VB does integers & rounding like this. I was always taught that 5 rounds up, then again I was taught integers drop there decimal points not round using MS Rounding.
 

hellman69

Member
Feb 15, 2003
180
0
71
Financially speaking, if the significant digit is odd, round up. If even, round down. This is how a bank does their rounding (I use to work on the mainframe at one). I believe VB's round function works the same way.

Trevor