|
-
Jan 14th, 2006, 03:38 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Rounding numbers in text box
hi guys,
how can i round the number entered in text boxes
saj
-
Jan 14th, 2006, 03:44 AM
#2
Re: Rounding numbers in text box
Hi
VB Code:
Text1.Text = Round(Text1.Text, 3) 'Round(Number, DecimalPlaces)
-
Jan 14th, 2006, 03:57 AM
#3
Thread Starter
Hyperactive Member
Re: Rounding numbers in text box
 Originally Posted by Andrew G
Hi
VB Code:
Text1.Text = Round(Text1.Text, 3) 'Round(Number, DecimalPlaces)
thank u for reply
i want to round the textboxes without any decimal part there. if i entered eg:- 12.5 it should be 13, if it s 12.4 it should be 12 only . i use the Round() function as u said, but not working properly
i tried like this.... round(textbox, 0)
saj
-
Jan 14th, 2006, 04:13 AM
#4
Re: Rounding numbers in text box
Damn, I thought VB would be smarter than that but oh well. try this
VB Code:
Private Function RoundNumber(Number As Double) As Long
txtparts = Split(Number, ".")
If UBound(txtparts) > 0 Then
If Mid(txtparts(1), 1, 1) >= 5 Then
RoundNumber = txtparts(0) + 1
Else
RoundNumber = txtparts(0)
End If
Else
RoundNumber = txtparts(0)
End If
End Function
Private Sub Command1_Click()
Text1.Text = RoundNumber(Text1.Text)
End Sub
But i'm pretty sure there should be a better way, i think
-
Jan 14th, 2006, 04:17 AM
#5
Re: Rounding numbers in text box
Your in luck
VB Code:
Text1.Text = Int(Int((Text1.Text + 0.5) * 100) / 100)
-
Jan 14th, 2006, 04:34 AM
#6
Re: Rounding numbers in text box
The reason for the rounding working as it does is because it uses bankers rounding, any number which is #.5 is rounded up if the # is odd and down if the # is even. Andrew G as it if you always want to round up on the .5 but i dont think theres any need for the *100 / 100
VB Code:
Text1.Text = Int(Val(Text1.Text) + 0.5)
casey.
-
Jan 14th, 2006, 04:39 AM
#7
Re: Rounding numbers in text box
What'd you know, it works without the 100's. The code is actually for calculating interest or something like that, and i just changed some small stuff and tested it and it worked so i didn't bother to check if i needed the 100's. 
Thanks for pointing that out
-
Jan 14th, 2006, 07:09 AM
#8
Thread Starter
Hyperactive Member
Re: [RESOLVED] Rounding numbers in text box
thanku andrew and vbasicgirl.....
saj
-
Apr 1st, 2009, 02:26 PM
#9
Junior Member
Re: [RESOLVED] Rounding numbers in text box
guys any help on how to generally round up any number to 2 decimal places plz not like round it up or down?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|