Mike Bishop -3

I am doing some calculations and the outcome of those sums are like 0.743449889958

the sum is calulated like so

textbox.Text = (textbox1 * _Units) / _priceincur

how would i format the string so that it only shows 0.7434 (rounded)

Luc001 77

Hi,

You can Try something like this:

``````Dim result as integer
result = (textbox1 * _Units) / _priceincur
Textbox1.Text=Math.Round(result,4)``````

I couldn't tested.

Mitja Bonca 557

As said, use Math.Round method. 1st parameter in this method in the actual value you want to round, while 2nd parameter is the number of decimals.
If you will do as Luc001 showed, will do just fine or:

``````Dim dValue As Decimal = 0D
If Decimal.TryParse(textBox1.Text.Trim(), dValue) Then
textBox2.Text = Math.Round((dValue * _Units / _priceincur), 4)
Else
MessageBox.Show("Value is not decimal, please repair it.")
End If``````

Mike Bishop -3

my fault, i only want this to two decimal places. IE 0.74

Mike Bishop -3

or if the number was 30.74 is would show as this

Mitja Bonca 557

I have explained how to set number of decimals. Have you read my post for above?

Math.Round(yourNumbe, numberOfDeciamls);
so:

``````textBox2.Text = Math.Round((dValue * _Units / _priceincur), 2)
Else``````

Mitja Bonca 557

and btw, about math priorities, and using brackets:
multiplying has an advantage over dividing, so you do not need any bracket when you do:

``A*B\C => this means A will be multiplied with B in the 1st place, then will be divided by C!``

Luc001 77

my fault, i only want this to two decimal places. IE 0.74

Hi,

Just to show you how you can change my snippet into a 2 decimal output:

``````Dim result as integer
result = (textbox1 * _Units) / _priceincur
Textbox1.Text=Math.Round(result,2)``````