This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Custom numeric format string to always display the sign
To format a double to certain precision in C# I write this:
d.ToString("#0.00");
What if I want to force a the sign to appear..
e.g
+2.54 and -2.54
Hope this will work.
YourDoublenumber.ToString("+#;#");
Related
This question already has answers here:
How to write Unicode characters to the console?
(5 answers)
Closed 4 years ago.
i want to ask if is possible to add in a string the "⚠" character and make it executable in console with Console.WriteLine().
you can use this code;
System.Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.WriteLine("⚠");
This question already has answers here:
How do I display a decimal value to 2 decimal places?
(19 answers)
Closed 7 years ago.
I need 45.7 to be 45.70
Math.Round(d, 2) have no effect.
Have tried with decimal and double type.
I would appreciate any kind of help.
You need to apply a string format:
string.Format("{0:N2}", 45.7)
Check here for docs on the string formatters
This question already has answers here:
How to find an average date/time in the array of DateTime values
(7 answers)
Closed 8 years ago.
I need to calculate the average the following observed dates:
1/7/2010
15/7/2011
17/6/2012
3/7/2013
How can I do that in asp.net or any other language. If there is any formula to do that.
You need to convert it to Ticks (this will convert it to System.Int64) and then do the average of them all.
See the following answer: https://stackoverflow.com/a/16683441/643761
This question already has answers here:
What's the main difference between int.Parse() and Convert.ToInt32
(13 answers)
Closed 9 years ago.
I would like to know if there is any difference between the captioned two methods?
string str = "14.75";
Console.WriteLine(Decimal.Parse(str));
Console.WriteLine(Convert.ToDecimal(str));
Can anyone please let me know? Thanks.
Decimal.Parse only supports parsing string values, whereas Convert takes other types as well, like, object, int, byte, DateTime etc.
This question already exists:
Closed 12 years ago.
Possible Duplicate:
String vs string in C#
What is the big difference between these datatypes? and were should I use it?
Short answer, there is no difference. They are just alias of each other, see
http://msdn.microsoft.com/en-us/library/ya5y69ds(VS.80).aspx for a complete list.
Have a look at: String vs string in C#