Using Math can help you. Also your "2.80" is wrong it will be "2.90". Try this
Dim core As Double = 3.481
REM: You can get or loop to your values using a loop instead of
' using just one example as I've done.
Dim RoundAwayFromZero As Double = Math.Round(core, 1, MidpointRounding.AwayFromZero)
Label1.Text = "The original value is: " & core & " The rounded value is: " & RoundAwayFromZero
If you are rounding up then your results should be 2.90, 3.50, and 0.80. IE, the first term is incorrect. There are standard algorithms for this which you can probably find in Wikipedia, such as this page: https://en.wikipedia.org/wiki/Rounding
Keep in mind that Math.Round exhibits (in my opinion) odd (no pun intended) behaviour. It behaves differently depending on whether the integer portion of a number is odd or even. For example
Math.Round(2.5) evaluates to 2.0
Math.Round(3.5) evaluates to 4.0
That's why I prefer to roll my own that always rounds x.5 up to the next integer. You can code this for any decimal place by multiplying by a factor of 10 and adding 0.5 before truncating. For example, to round 2.56 to one decimal
Multiply by 10 (to give 25.6)
Add 0.5 (to give 26.1)
Truncate (to give 26.0)
Divide by 10 (to give 2.6)
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...