The examples in this article describe C # decimal format usage. Share to everyone for your reference, specific as follows:
1.ToString () method
Double d=12345678.2334;
Console.WriteLine (d.tostring ("F2")); 1234.23
Console.WriteLine (d.tostring ("###,###.00"));//12,345,678.23
2.math.round () method
Math.Round (3.44, 1); Returns 3.4.
Math.Round (3.45, 1); Returns 3.4.
Math.Round (3.46, 1); Returns 3.5.
Math.Round (3.445, 1); Returns 3.4.
Math.Round (3.455, 1); Returns 3.5.
Math.Round (3.465, 1); Returns 3.5.
Math.Round (3.450, 1); Returns 3.4. (complement 0 is invalid)
Math.Round (3.4452, 2); Returns 3.45.
Math.Round (3.4552, 2); Returns 3.46.
Math.Round (3.4652, 2); Returns 3.47.
"Four homes six into five, after five Non-zero into one, five after zero to see the odd couple, five ago for me to give up, five ago for the odd to enter a"
The short one is called "four homes, six, five sets of dolls."
3.double. Parse () method
Double d=1.12345;
D=double. Parse (D.tostring ("0.00")); 1.12
4. Output percent Sign
System.Globalization.NumberFormatInfo Provider = new System.Globalization.NumberFormatInfo ();
Provider. Percentdecimaldigits = 2;//A decimal point to retain several digits.
Provider. Percentpositivepattern = where 1;//percent signs appear.
Double result = (double) 1/3;//Be sure to use double type.
Console.WriteLine (Result. ToString ("P", provider)); 33.33%
//or
Console.WriteLine ((result*100). ToString ("#0. #0") + "%");
5.string.format () method
String str1 = String.Format ("{0:n1}", 56789); result:56,789.0
String str2 = String.Format ("{0:n2}", 56789);//result:56,789.00
string str3 = String.Format ("{0:n3}", 56789); result:56,789.000
String str8 = String.Format ("{0:f1}", 56789);//result:56789.0
string STR9 = String.Format ("{0:f2}", 56789); result:56789.00
String str11 = (56789/100.0). ToString ("#.##"); result:567.89
String str12 = (56789/100). ToString ("#.##"); result:567
Read more about C # Interested readers can view the site topics: "C # form Operation Tips Summary", "C # Common control usage Tutorial", "WinForm Control Usage Summary", "C # Programming Thread Usage Skills summary", "C # Operation Excel Skills Summary", "C # Summary of operational skills in XML files, C # tutorial on data structure and algorithms, C # array operation techniques Summary, and C # Introduction to object-oriented Programming
I hope this article will help you with C # programming.