Well this is an old question and I indeed made use of some of the answers shown here. Nevertheless, in my particular scenario it was possible that the double
value that I wanted to convert to decimal
was often bigger than decimal.MaxValue
. So, instead of handling exceptions I wrote this extension method:
public static decimal ToDecimal(this double @double) =>
@double > (double) decimal.MaxValue ? decimal.MaxValue : (decimal) @double;
The above approach works if you do not want to bother handling overflow exceptions and if such a thing happen you want just to keep the max possible value(my case), but I am aware that for many other scenarios this would not be the expected behavior and may be the exception handling will be needed.