Convert to string with a [+] or a [-] sign symbol
-
sign symbol for example I have: double x = 500.12; double y = -500.12; I want x to be diplayed as: +500.12 and y to be displayed as: -500.12 Please help
-
sign symbol for example I have: double x = 500.12; double y = -500.12; I want x to be diplayed as: +500.12 and y to be displayed as: -500.12 Please help
The negative number should come out with a - sign already. So once you've used .ToString, if the first char isn't a '-' then put a '+' at the start:
double x = 500.12;
double y = -500.12;string sX;
string sY;sX = x.ToString();
if(!sX.StartsWith("-"))
sX = "+" + sX;sY = y.ToString();
if(!sY.StartsWith("-"))
sY = "+" + sY;Console.WriteLine(sX + "\n" + sY);
The output should be:
+500.12 -500.12
My current favourite word is: PIE! Good ol' pie, it's been a while.
-
sign symbol for example I have: double x = 500.12; double y = -500.12; I want x to be diplayed as: +500.12 and y to be displayed as: -500.12 Please help
Thanks for the opportunity to look into this.:-D
System.Console.WriteLine ( ( 500.12).ToString("+#.##;-#.##" ) ) ;
System.Console.WriteLine ( (-500.12).ToString("+#.##;-#.##" ) ) ; -
Thanks for the opportunity to look into this.:-D
System.Console.WriteLine ( ( 500.12).ToString("+#.##;-#.##" ) ) ;
System.Console.WriteLine ( (-500.12).ToString("+#.##;-#.##" ) ) ;Works like a charm. Thanks.