Round a number in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This tutorial will show you how to round a decimal to a whole number in Visual basic .NET

Add a TextBox and a Button

TextBox is used to enter the decimal number, then the user will click on the button, and TextBox will show the rounded number

round number in visual basic

Add the following code to the round button click event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        Dim a As Single
        Dim b As Double
        b = Convert.ToDouble(TextBox1.Text)
        a = Math.Round(b)

        TextBox1.Text = a
    End Sub

round a decimal in vb.net


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.