Using Math.Pow Method to Compute Exponents in C#

by Ginktage | Saturday, Jan 14, 2012 | 418 views

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.
Like it? Share it!

Leave A Response