Limit % digits to 2 in text box

Hi
I have the following code and would like to limit the response in my txtbox so there is only a whole number could anyone please show me the code i need to use.

Private Sub txtMorActS_Change()

If IsNumeric(txtMorEst(0).Text) And IsNumeric(txtMorActS.Text) Then
If CDbl(txtMorActS.Text) < 0.00001 Then
txtPercent.Text = "0"
Else
txtPercent.Text = Format(CDbl(txtMorEst(0).Text) / CDbl(txtMorActS.Text), "Percent")
End If
End If

txtMorMixS.Text = txtMorEst(0).Text * 16 * 6 / 1925

End Sub

Many Thanks
Andy
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RetiredCommented:
Hi Andy

If you only want up to two integer digits remaining, you need:

txtPercent.Text = Format(CDbl(txtMorEst(0).Text) / CDbl(txtMorActS.Text), "#0")
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

RetiredCommented:
That does not multiply by 100 or add the percent sign, so you might want:
txtPercent.Text = Format(100*(CDbl(txtMorEst(0).Text) / CDbl(txtMorActS.Text)) , "#0") & "%"
0
Commented:
hi

you could use int to return only the whole numbers:

txtMorMixS.Text = int(txtMorEst(0).Text * 16 * 6 / 1925)

0
Author Commented:
Hi Graham
have used your code and works well thanks, does annyone know if the following is possible?

for example
txtboxEstimate = 100
txtboxActual = 137

I want txtbox3 to show the % that the actual is over the estimate i.e the % of 37 above 100 and also be able to show negatives!!!

Many Thanks
Andy
0
Commented:
try this

txtbox3.text = (val(txtboxActual.text)- val(txtboxEstimate.text))/val(txtboxEstimate.text)*100
0
Author Commented:
Hi ee
This doesnt seem to be working for me

Thanks
Andy
0
Commented:
can you explain what you mean by not working?

is it producing an error or is it returning an incorrect value?
0
Author Commented:
Sorry its returning an incorrect - value

Thanks
Andy
0
Commented:
can you post the code and the values of txtboxActual, txtboxEstimate & txtbox3?
0
Author Commented:
hI ee

Sorry got it working

Thanks
Andy
0
RetiredCommented:
Perhaps just need this, Andy?

txtbox3.text =  (txtboxActual.text / txtboxEstimate.text)*100
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.