C 的String Format格式化舉例

2021-04-13 09:24:26 字數 1116 閱讀 6890

c#的string.format格式化舉例

stringstr1 =string.format("",56789);               //result: 56,789.0

stringstr2 =string.format("",56789);               //result: 56,789.00

stringstr3 =string.format("",56789);               //result: 56,789.000

stringstr8 =string.format("",56789);               //result: 56789.0

stringstr9 =string.format("",56789);               //result: 56789.00

stringstr11 =(56789 / 100.0).tostring("#.##");           //result: 567.89

stringstr12 =(56789 / 100).tostring("#.##");             //result: 567

c 或 c

貨幣console.write("", 2.5);  //$2.50

console.write("", -2.5); //($2.50)

d 或 d

十進位制數

console.write("", 25);  //00025

e 或 e

科學型console.write("", 250000);  //2.500000e+005

f 或 f

固定點console.write("", 25);  //25.00

console.write("", 25);  //25

g 或 g

常規console.write("", 2.5);  //2.5

n 或 n

數字console.write("", 2500000);  //2,500,000.00

x 或 x

十六進製制

console.write("", 250);  //fa

console.write("", 0xffff);  //ffff

C 中String Format的使用

說明 string.format 將指定的 string 中的每個格式項替換為相應物件的值的文字等效項。例子 int ivisit 100 string szname jackfled response.write string.format 您的帳號是 訪問了 次.szname,ivisit c ...

C 的String Format格式化引數

n或n 數字 console.write 2500000 2,500,000.00 c或c 貨幣 console.write 2.5 2.50 console.write 2.5 2.50 d或d 十進位制數 console.write 25 00025 e或e 科學型 console.write ...

String format方法的應用

string str null str string.format hi,s 小超 system.out.println str str string.format hi,s s s 小超 是個 大帥哥 system.out.println str system.out.printf 字母c的大寫是...