Specified cast is not valid.. how to resolve this

Use Convert.ToDouble(value) rather than (double)value. It takes an object and supports all of the types you asked for! 🙂

Also, your method is always returning a string in the code above; I’d recommend having the method indicate so, and give it a more obvious name (public string FormatLargeNumber(object value))

Leave a Comment