Your error here is you are trying to format a string, not a number. String.Format()
can format only if you pass a number. So you just simply need to change parameter from string to double:
public static MvcHtmlString FormatString(this HtmlHelper helper, double numberToFormat, int format)
And don't convert numbers in the view:
@Html.FormatString(i.ActivityValue, i.DataTypeId)
If you have not only double values, but also other types (like float or decimal) you can use object
instead of double
:
public static MvcHtmlString FormatString(this HtmlHelper helper, object numberToFormat, int format)