Is there any way I can specify a standard or custom numeric format string to always output the sign, be it +ve or -ve (although what it shoudl do for zero, I'm not sure!)
+12
A:
Yes, you can. There is conditional formatting. See Conditional formatting in MSDN
eg:
string MyString = number.ToString("+#;#");
Where each section separated by a semicolon represents positive and negative numbers
or:
string MyString = number.ToString("+#;#;0");
if you don't want the zero to have a plus sign.
gcores
2008-12-07 22:40:09
Excellent - thanks!
Craig Shearer
2008-12-07 22:57:55
+9
A:
Beware, when using conditional formatting the negative value doesn't automatically get a sign. You need to do
string MyString = number.ToString("+#;-#;0");
Luk
2009-02-17 13:46:03