I\'m not that great with maths and C# doesn\'t seem to provide a power-of function so I was wondering if anyone knows how I would run a calculation like this:
Following is the code calculating power of decimal value for RaiseToPower for both -ve and +ve values.
public decimal Power(decimal number, decimal raiseToPower)
{
decimal result = 0;
if (raiseToPower < 0)
{
raiseToPower *= -1;
result = 1 / number;
for (int i = 1; i < raiseToPower; i++)
{
result /= number;
}
}
else
{
result = number;
for (int i = 0; i <= raiseToPower; i++)
{
result *= number;
}
}
return result;
}