[Webinar] Streamline your web hosting managementRegister Today

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

# 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
• 4
• 4
• 3
2 Solutions

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

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

## Featured Post

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