How to Round a Number in Visual Basic
- 1). Create a new project by clicking "File" and "New Project." Select "Console Application" as the project type. Later, you can duplicate the same code in a graphical user interface (GUI) based application. Name the project "NumberRoundingTutorial."
- 2). Create a number to round by pasting the following code into your project:
Dim mynum as Double
mynum = 0.5 - 3). Paste the following code to round the number up to the next highest whole number:
dim roundup as integer = math.ceiling(mynum) - 4). Paste the following to round the number down to the next lowest whole number:
dim rounddown as integer = math.floor(mynum) - 5). Paste the following to round the number to the nearest whole number, up or down:
dim round as integer = math.round(mynum, MidPointRounding.AwayFromZero)
Source...