Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Power round Remainder Math operations using Math class VB and C#.net 2.0

Author: Maliha Atteeq
Download Source Code : 972_Math.zip

In this simple article you will learn that how we can get power and remainder and how to round a number using "Math class" in VB and C# (.net 2.0).

 Power:

To get the power of a number with we have a static function of Math class named Pow (). This function takes two parameters of double type first is base and second is power and returns the answer as double.

To demonstrate make a window application. Drag two text boxes and one button on form.

Now write the following code on Button click event:

C#

private void btn_pow_Click(object sender, EventArgs e)

        {

            string str = txt_base.Text;

            string str2 = txt_powval.Text;

            double bs = Convert.ToDouble(str);

            double val = Convert.ToDouble(str2);

            double ans;

            ans = System.Math.Pow(bs, val);

            MessageBox.Show(ans.ToString());

        }

VB

Private Sub btn_pow_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim str As String = txt_base.Text

        Dim str2 As String = txt_powval.Text

        Dim bs As Double = Convert.ToDouble(str)

        Dim val As Double = Convert.ToDouble(str2)

        Dim ans As Double

        ans = System.Math.Pow(bs, val)

        MessageBox.Show(ans.ToString())

    End Sub

This is simple code to get the power.

Remainder:

To get the remainder we have a static function of Math class named IEEERemainder (). This function takes two parameters of double type first the number to whom you want to divide and second is divisor and returns the remainder as double.

To demonstrate make a window application. Drag two text boxes and one button on form.

Now write the following code on Button click event:

C#

private void btn_rem_Click(object sender, EventArgs e)

        {

            string str = txt_first.Text;

            string str2 = txt_second.Text;

            double f = Convert.ToDouble(str);

            double s = Convert.ToDouble(str2);

            double ans;

            ans = System.Math.IEEERemainder(f, s);

            MessageBox.Show(ans.ToString());

        }

VB

Private Sub btn_rem_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim str As String = txt_first.Text

        Dim str2 As String = txt_second.Text

        Dim f As Double = Convert.ToDouble(str)

        Dim s As Double = Convert.ToDouble(str2)

        Dim ans As Double

        ans = System.Math.IEEERemainder(f, s)

        MessageBox.Show(ans.ToString())

    End Sub

This is simple code to get the remainder.

Round:

To round a floating point number we have a static function of Math class named Round (). This function takes and returns a double value.

To demonstrate make a window application. Drag one text box and one button on form.

Now write the following code on Button click event:

C#

private void btn_round_Click(object sender, EventArgs e)

        {

            string str = txt_round.Text;

            double value=Convert.ToDouble(str);

            double ans;

            ans=System.Math.Round(value);

            MessageBox.Show("ANS =" + ans.ToString());

        }

 

VB

Private Sub btn_round_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim str As String = txt_round.Text

        Dim value As Double = Convert.ToDouble(str)

        Dim ans As Double

        ans = System.Math.Round(value)

        MessageBox.Show("ANS =" & ans.ToString())

    End Sub

This is simple code to round a number.

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP MATH APPLICATION";          

        }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DEVASP MATH APPLICATION"

End Sub

 

This simple article tells that how we can get power and remainder and how to round a number using "Math class" in VB and C# (.net 2.0).

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Multiplication power logarithm Math operations using Math class VB and C#.net 2.0

Disclaimer - Privacy
© 2002-2017 DevASP.net