This article describes the usage of C# decimal point formatting. Share it for your reference, as follows:
()method
double d=12345678.2334; (("F2")); //1234.23 (("###,###.00")); //12,345,678.23
()method
(3.44, 1); //Returns 3.4. (3.45, 1); //Returns 3.4. (3.46, 1); //Returns 3.5. (3.445, 1); //Returns 3.4. (3.455, 1); //Returns 3.5. (3.465, 1); //Returns 3.5. (3.450, 1); //Returns 3.4. (Supplementing 0 is invalid)(3.4452, 2); //Returns 3.45. (3.4552, 2); //Returns 3.46. (3.4652, 2); //Returns 3.47.
"Four rounds six into five, consider the five, and the five after five is not zero, and then the five after five is zero, and the odd and even, and the five before five is even, and the five before five is even, and the other should be abandoned. When the five is odd, it should be entered."
A shorter mantra is called "four rounds, six entries, five entries"
()method
double d=1.12345; d=(("0.00")); //1.12
4. Output percent sign
provider = new (); = 2;//Retain a few digits of decimal places. = 1;//Where does the percent sign appear?double result = (double)1 / 3;//Be sure to use the double type.(("P", provider)); //33.33% //or((result*100).ToString("#0.#0")+"%");
()method
string str1 = ("{0:N1}",56789); //result: 56,789.0 string str2 = ("{0:N2}",56789); //result: 56,789.00 string str3 = ("{0:N3}",56789); //result: 56,789.000 string str8 = ("{0:F1}",56789); //result: 56789.0 string str9 = ("{0:F2}",56789); //result: 56789.00 string str11 =(56789 / 100.0).ToString("#.##"); //result: 567.89 string str12 =(56789 / 100).ToString("#.##"); //result: 567
For more information about C# related content, please check out the topic of this site:Summary of C# form operation skills》、《Tutorial on the usage of common C# controls》、《Summary of WinForm control usage》、《Summary of thread usage techniques for C# programming》、《Summary of C# operation skills》、《Summary of XML file operation skills in C#》、《C# data structure and algorithm tutorial》、《Summary of C# array operation skills"and"Introduction to C# object-oriented programming tutorial》
I hope this article will be helpful to everyone's C# programming.