Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does one round down to the nearest INT in VB6?

Status
Not open for further replies.

Albion

IS-IT--Management
Aug 8, 2000
517
0
0
US
I have tried these three things.

Dim Var as Double

Var = 9

Me.text1 = Round(Var / 5, 0)
Me.text1 = Round(Var / 5, 0) -1
Me.text1 = FormatNumber(Var / 5, 0)
Me.text1 = CInt(Var / 5)

All of these return the number 2 to Me.text1 except for the second which fails on Var = multiples of 5. I expected the third to work because 9/5 = 1.8, format the number to 0 decimal places and you get 1 but I guess Microsoft uses different logic then I do. :) Is there a way to round down in VB or does everything Round up? I have

Basically I have a program where 0 to 4 = 0, 5 to 9 = 1, 10 to 14 = 2, etc... So I need to round down.

Thanks





-cm
 
Try this:
Code:
Me.text1 = Round((Var / 5) - 0.5 , 0)
 
Thanks for the help, that works. :)

-cm
 
you can try Int(9/5)
it is supposed to return the number without the decimal part.

Magoo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top