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 .

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 ;

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
How to convert Array to List in C#?
Want to convert array of strings to List of strings in C# ? . Below is a sample code to illustrate t...