Don't do that.
Your code is extremely inefficient.
You should change it to
double convertedTop = Convert.ToDouble(top);
If the compile-time type of top
is decimal
or decimal?
(as opposed to object
or IConvertible
or ValueType
), you can use an even-more-efficient compile-time cast:
double convertedTop = (double)top;
To answer the question, top.ToString()
is culture-sensitive.
You need to pass CultureInfo.InvariantCulture
there too.
Nullable<T>
doesn't lift ToString(IFormatProvider)
, so you'll need to do that on Value
and handle null
explicitly.