PDA

View Full Version : [SOLVED:] Round Up the answer to a calculation which is being performed in VB



MarkB2908
02-26-2021, 05:36 AM
Hi there.

Within a VB procedure i have a very simple calculation i.e. Number 1 divided by Number 2 = Answer.
The results returned always have multiple decimal places i.e. 98.827876.

I would like to pass / insert this value into a Textbox which has been embedded into a Worksheet, but I need it to appear as a % with either 1 or no decimal places.

I've added the % symbol in the simplest that I know i.e. TextboxText = Answer & "%" but the end result shows as 98.827876% (I need to lose some/all of the decimal places)

Is it possible to Round Up the "Answer" to the calculation being performed inside the procedure within VB ?

or

Can I limit the value which is being passed to the embedded textbox so that the end result is simply 98.8% or 99% ?

Hope this makes sense.

Any help would be greatly appreciated.

arangogs
02-26-2021, 08:45 AM
Hi Mark,

round function will do what you are looking for.

TextboxText = Round(Answer,2)

Paul_Hossler
02-26-2021, 02:36 PM
'RoundUp' or just 'Round'?


TextBox1.Text = Format(.9849, "0#.0%")

28023

MarkB2908
02-26-2021, 05:08 PM
Hi Mark,

round function will do what you are looking for.

TextboxText = Round(Answer,2)

Brilliant. Thank you. and so simple too.

MarkB2908
02-26-2021, 05:09 PM
ignore

MarkB2908
02-26-2021, 05:09 PM
'RoundUp' or just 'Round'?


TextBox1.Text = Format(.9849, "0#.0%")

28023

Thank you