You can use pure math to get the desired result which is more efficient than string conversions, but it's tricky to resolve the right side after the decimal separator and convert it to an integer.
With following methods the query to get the result is easy:
decimal result = list.MaxBy(GetValueAfterDecimalSeparator);
public static int GetValueAfterDecimalSeparator(decimal d)
{
decimal normalized = Normalize(d); // remove trailing zeros
int countDecimalNumbers = BitConverter.GetBytes(decimal.GetBits(normalized)[3])[2];
decimal leftValue = System.Math.Floor(normalized);
decimal rightValue = Math.Abs(leftValue - normalized);
try
{
int multiplier = (int)Math.Pow(10, countDecimalNumbers);
return Decimal.ToInt32(Decimal.Multiply(rightValue, multiplier));
}
catch(OverflowException)
{
return int.MaxValue;
}
}
public static decimal Normalize(decimal value)
{
return value/1.000000000000000000000000000000000m;
}
The Normalize
method came from here.