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)
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)
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.
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
my fault, i only want this to two decimal places. IE 0.74
or if the number was 30.74 is would show as this
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
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!
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)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.