[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

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
0
samandrew
Asked:
samandrew
  • 4
  • 4
  • 3
2 Solutions
 
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
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now