In C #, we all encounter this situation where data of the double type needs to be formatted (retain N unvalid numbers) or N as decimal places.Double. tostring ("parameter ");. The following describes several common methods.
Double temp = 3.1415926;
(F)Fixed Point:String str1 = temp. tostring ("f1"); // returns the result of rounding a decimal number to 3.1.
(F)Fixed Point:String str2 = temp. tostring ("F2"); // retain two decimal places, rounding the following result and so on: 3.14
(N)Number:String str2 = temp. tostring ("N"); // reserved result: 3.14
(G) General (Default ):String str2 = temp. tostring ("G"); // reserved result: 3.1415926
(P)Percent:String str2 = temp. tostring ("p"); // reserved result: 314.16%
(E)Scientific:String str2 = temp. tostring ("e"); // reserved result E: 3.141593e + 000
(C)Currency:String str2 = temp. tostring ("C"); // reserved result: ¥3.14