ToString format causes InvalidCastException
I am using .ToString("#,##0.00") to format a number.
I'm sure I have used this before but today it doesn't work.
I want to format a System.Double value from the datatable like this 12345.6789 to 12,345.68
Code:
myString = dt.Rows(i)("column_name").ToString("#,##0.00")
gives a System.InvalidCastException:
Conversion from string "#,##0.00" to type 'Integer' is not valid.
Any ideas?
Re: ToString format causes InvalidCastException
Try:
dt.Rows(i)("column_name").Value.ToString("#,##0.00")
instead.
-tg
Re: ToString format causes InvalidCastException
You'd could use String.Format()
Code:
Code:
String.Format(dt.Rows(i)("column_name").Value.ToString,{0:#,##0.00}
Or something like that