It seems as though String.Format won’t format a string as an input. Am I doing something wrong, or is this just native behavior?
Input : 0.37
This doesn’t work.
string x = String.Format('{0:P}', myString)
Output : 0.37
This does.
string x = String.Format('{0:P}', Convert.ToDecimal(myString))
Output : 37.00 %
I believe this is expected behavior for ‘composite formatting’.
Your first example is attempting to apply numerical formatting rules to a string. Your second example is attempting to apply numerical formatting rules to a number that can have decimal positions.
See this article on MSDN for more information.