Question Help with Math.round

Stirlim

New member
Joined
Mar 6, 2013
Messages
3
Programming Experience
Beginner
Hi, this may seem like a nooby question.If i try use math.round and it doesnt appear to work.

This is an image of my code,it went kinda buggy when i pasted it it :L
Im very inxperienced and any help would be appreciated :)
Untitled.png
Any advice once more is appreciated
 
Hi,

Welcome to the forum but please DO NOT say things like:-

i try use math.round and it doesnt appear to work.

Since this does not tell us anything about the problem that you are having so their is no way for us to help you.

As an example, if I tested this myself with a random value of 1.23456:-

VB.NET:
MsgBox(Math.Round(1.23456, 2, MidpointRounding.AwayFromZero))

I get 1.23 which is what I would expect.

So what is it that you are EXPECTING and what is it that you are GETTING that makes you think this is not working.

Cheers,

Ian
 
Round is a function, the result is the return value, it does not change the input value/variable. Example of correct usage:
Dim result = Math.Round(value, 2, MidpointRounding.AwayFromZero)
 
Please turn Option Strict On at the top of your code.
You are attempting to do math with a string! Of course it won't work.
Console.ReadLine only works with string input, which must then be converted into the correct number type.

Dim order As Double, snum As String
Console.Write("Enter value: ")
snum = Console.ReadLine()
Double.TryParse(snum, order)
'etc

Now you can use the numeric value of order to test for the correct range and round it out.
 
String*
also thanks JohnH i got it to work. One question if i put in a number as an integer value(dimmed as decimal) like 90 how could i get it to 90.00?
 
You could use the .ToString() method to display it with a format
VB.NET:
Dim i as integer = 90
MessageBox.Show(i.ToString("F2"))

Should result in a messagebox displaying 90.00
 
Back
Top