Using Math.Pow Method to Compute Exponents in C#

If you require to compute exponential values like finding the square of the number etc , the Math.Pow method in c# could be handy for you to try .

The Math.Pow method is defined in the “System” namespace .

Using Math.Pow Method to Compute Exponents in C#

To use the method “Math.Pow” , you should first include the namespace System

using System;

The Math.Pow accepts 2 parameters

  1. number to be raised to a power
  2. number that specifies a power

Note that the parameters to the Math.Pow must be of type double .

For example , i can use the method

double value1 = Math.Pow(3, 3);

The above code is equivalent to 3 ^ 3 .

Below is a sample function that i used for my new WP7 App which uses the Math.Pow function

private decimal CalclateEMI(decimal LoanAmount,int Months,double Interest) 
{
   Interest = (Interest / 100)/12;             
   decimal EMI = (LoanAmount * (Decimal)Interest) * (Decimal)( Math.Pow((1+ Interest), Months) / ((Math.Pow((1+ Interest ), Months)) - 1));         
   return EMI; 
}

Math.Pow is one of the useful method that provides a clear way to calculate exponential values ;

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...