Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion from string "0.##" to type 'Integer' is not valid

Tags:

asp.net

vb.net

i am doing a simple conversion from decimal to string and stripping trailing zeros like so:

argCat.ToString("0.##")

however, i keep getting the following error:

Conversion from string "0.##" to type 'Integer' is not valid.

am i missing something?

like image 770
Madam Zu Zu Avatar asked Apr 19 '26 22:04

Madam Zu Zu


2 Answers

This would happen if argCat is of a type that does not have a ToString() overload that accepts a parameter.

In such a case, your code is parsed as ToString()("0.##"); the "0.##" becomes an argument to the indexer in the String returned by ToString().
You then get this misleading error because that indexer takes an int, not a string.

like image 149
SLaks Avatar answered Apr 21 '26 13:04

SLaks


string str = String.Format("{0:C}", argCat);

like image 43
Sev Avatar answered Apr 21 '26 13:04

Sev