Muj Muj - 1 year ago 112 Question

Easiest way on multiplying number to percent value

Hello :) I have a formula like this

Dim numbHolder as Decimal = 'Anything i will send'
If val(txtbox1.text) <= 9 then
txtbox2.text = numbHolder * (0.0 & val(txtbox1.text))
txtbox2.text = numbHolder * (0. & val(txtbox1.text))
end if

is there an easiest way or function that i can use to multiply any number in percentage?
because in my scenario i have to check it first if the number is not greater than 9
so that i can use correct formula like
and so on..

Answer Source

If I were you I would avoid mixing Val and calculations in the one place. Try separating the parsing and populating text fields with the calculation like this:

' Parse/Load Values
Dim numbHolder As Decimal = 10 'Anything i will send'
Dim percentage As Decimal = CType(Val(txtbox1.Text), Decimal) / 100

' Calculate
Dim result = numbHolder * percentage

' Populate
txtbox2.Text = result.ToString()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download