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
samandrewAsked:
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.

GrahamSkanRetiredCommented:
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

Your issues matter to us.

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

Start your 7-day free trial
GrahamSkanRetiredCommented:
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
ee_rleeCommented:
hi

you could use int to return only the whole numbers:

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




0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

samandrewAuthor 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
ee_rleeCommented:
try this

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

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

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

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

Sorry got it working

Thanks
Andy
0
GrahamSkanRetiredCommented:
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.