[Solved] C# Linq query calculate percentage from integer [closed]


Convert the list to a decimal list, and use something like the following :

var list = new List<decimal> { 2512793, 119176, 83599, 45613, 43352 };
decimal sum = list.Sum();
var perc = list.Select(x => (x / sum) * 100);

Alternatively, you can cast each value as decimal.

Or Alternatively as @James Pointed out there is no need to multiply by 100 if you need to output the value.

var perc = list.Select(x => x / sum);
Console.WriteLine(perc.FirstOrDefault().ToString("P")); // Output the first value

4

solved C# Linq query calculate percentage from integer [closed]