ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Get Percentage

Gets the specified percentage of the given value.

Source

/// <summary>
/// Get a certain percentage of the specified number.
/// </summary>
/// <param name="value">The number to get the percentage of.</param>
/// <param name="percentage">The percentage of the specified number to get.</param>
/// <returns>The actual specified percentage of the specified number.</returns>
public static double GetPercentage(this double value, int percentage)
{
    var percentAsDouble = (double)percentage / 100;
    return value * percentAsDouble;
}

Example

var value = 100d;
var result = value.GetPercentage(50); //Get 50% of 100 which is 50.

Author: Nicky Ernste

Submitted on: 25 aug. 2017

Language: C#

Type: Double

Views: 5764