Computing.Net > Forums > Programming > Numbers in VB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Numbers in VB

Reply to Message Icon

Name: bertyzz
Date: December 8, 2002 at 06:00:57 Pacific
OS: Xp Pro
CPU/Ram: 1.1 Gig 256 DDR
Comment:

Hi guys,

Im having a spot of trouble rounding numbers in Vb. Can anyone tell me how to round numbers down?

eg. I have a number such as 109.62 but this always gets rounded up to 110.
Is there away that I can get it rounded down to 109?

Thanks guys

Berty



Sponsored Link
Ads by Google

Response Number 1
Name: HiJinx
Date: December 8, 2002 at 11:01:09 Pacific
Reply:

I did a very quick check and didn't come up with a suitable built-in function to always round down (but that doesn't mean that there isn't one).

However, you could just compare the rounded value to the unrounded value. If the rounded value is greater (VB rounded up), just subtract 1 from it.


0

Response Number 2
Name: Jason
Date: December 8, 2002 at 12:23:23 Pacific
Reply:

What about this

Number = int(number)


0

Response Number 3
Name: HiJinx
Date: December 8, 2002 at 12:39:37 Pacific
Reply:

Yep, Int(x) works. I was converting with CInt(), which would round to the nearest instead of just dropping the decimal.


0

Response Number 4
Name: BaBa
Date: December 8, 2002 at 20:10:58 Pacific
Reply:

Hi,
you can use the Fix functon

put a command button and a texbox on the form


Private Sub Command1_Click()
Dim num As Single
num = Text1.Text
Text1.Text = Fix(num)
End sub

Have fun!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Numbers in VB

Converting numbers in vbs www.computing.net/answers/programming/converting-numbers-in-vbs/10268.html

Multiplication in VB www.computing.net/answers/programming/multiplication-in-vb/5565.html

winsock error 10054 in VB www.computing.net/answers/programming/winsock-error-10054-in-vb/4027.html