Why do I get InvalidCastException when casting a double to decimal
A suggestion: try using Convert.ToDecimal() instead of direct casting.
Eric Lippert has blogged about exactly this in depth. I agree it's unintuitive at first, but he explains it well: Representation and Identity
You need to cast it to a double first as row[denominator]
is a double boxed as an object
i.e.
decimal d = (decimal)((double)row[denominator]);