C#格式化數(shù)值結(jié)果表_第1頁
C#格式化數(shù)值結(jié)果表_第2頁
C#格式化數(shù)值結(jié)果表_第3頁
C#格式化數(shù)值結(jié)果表_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、C#格式化數(shù)值結(jié)果表字符說明示例輸出C貨幣string.Format("0:C3", 2)2.000D十進(jìn)制string.Format("0:D3", 2)002E科學(xué)計(jì)數(shù)法1.20E+0011.20E+001G常規(guī)string.Format("0:G", 2)2N用分號(hào)隔開的數(shù)字string.Format("0:N", 250000)250,000.00X十六進(jìn)制string.Format("0:X000", 12)Cstring.Format("0:000.000", 1

2、2.2)012.200StringsThere really isn't any formatting within a strong, beyond it's alignment. Alignment works for any argument being printed in a String.Format call.  SampleGeneratesString.Format("->1,10<-", "Hello");-> Hello<-String.Format("->1,-10

3、<-", "Hello");->Hello <-NumbersBasic number formatting specifiers: SpecifierTypeFormat Output (Passed Double 1.42)Output (Passed Int -12400)cCurrency0:c1.42-12,400dDecimal (Whole number)0:dSystem.FormatException-12400eScientific0:e1.420000e+000-1.240000e+004fFixed point0

4、:f1.42-12400.00gGeneral0:g1.42-12400nNumber with commas for thousands0:n1.42-12,400rRound trippable0:r1.42System.FormatExceptionxHexadecimal0:x4System.FormatExceptioncf90Custom number formatting: SpecifierTypeExample Output (Passed Double 1500.42)Note0Zero placeholder0:00.00001500.4200Pads with

5、 zeroes.#Digit placeholder0:(#).#(1500).42 .Decimal point0:0.01500.4 ,Thousand separator0:0,01,500Must be between two zeroes.,.Number scaling0:0,. 2Comma adjacent to Period scales by 1000.%Percent0:0%150042%Multiplies by 100, adds % sign.eExponent placeholder0:00e+015e+2Many exponent forma

6、ts available.;Group separatorsee below  The group separator is especially useful for formatting currency values which require that negative values be enclosed in parentheses. This currency formatting example at the bottom of this document makes it obvious:DatesNote that date formatting is

7、especially dependant on the system's regional settings; the example strings here are from my local locale. SpecifierTypeExample (Passed System.DateTime.Now)dShort date10/12/2002DLong dateDecember 10, 2002tShort time10:11 PMTLong time10:11:29 PMfFull date & time December 10, 2002 10:11 P

8、MFFull date & time (long)December 10, 2002 10:11:29 PMgDefault date & time10/12/2002 10:11 PMGDefault date & time (long)10/12/2002 10:11:29 PMMMonth day patternDecember 10rRFC1123 date stringTue, 10 Dec 2002 22:11:29 GMTsSortable date string2002-12-10T22:11:29uUniversal sortable, local t

9、ime2002-12-10 22:13:50ZUUniversal sortable, GMTDecember 11, 2002 3:13:50 AMYYear month patternDecember, 2002The 'U' specifier seems broken; that string certainly isn't sortable.Custom date formatting: SpecifierTypeExample Example OutputddDay0:dd10dddDay name0:dddTueddddFull day name

10、0:ddddTuesdayf, ff, .Second fractions0:fff932gg, .Era0:ggA.D.hh2 digit hour0:hh10HH2 digit hour, 24hr format0:HH22mmMinute 00-590:mm38MMMonth 01-120:MM12MMMMonth abbreviation0:MMMDecMMMMFull month name0:MMMMDecemberssSeconds 00-590:ss46ttAM or PM0:ttPMyyYear, 2 digits0:yy02yyyyYear0:yyyy2002zzTimezo

11、ne offset, 2 digits0:zz-05zzzFull timezone offset0:zzz-05:00:Separator0:hh:mm:ss10:43:20/Separator0:dd/MM/yyyy10/12/2002Enumerations SpecifierTypegDefault (Flag names if available, otherwise decimal)fFlags alwaysdInteger alwaysxEight digit hex.Some Useful ExamplesString.Format("0:#,#0.00;(

12、#,#0.00);Zero", value);This will output "1,240.00" if passed 1243.50. It will output the same format but in parentheses if the number is negative, and will output the string "Zero" if the number is zero.This will output "(800) 555-1212". 變量.ToString()字符型轉(zhuǎn)換 轉(zhuǎn)為字符串 12345.ToString("n"); /生成 12,345.00 12345.ToString("C"); /生成 ¥12,345.

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論