Format 函数用法

Format 函数用法

ID:40529139

大小:24.57 KB

页数:6页

时间:2019-08-04

Format  函数用法_第1页
Format  函数用法_第2页
Format  函数用法_第3页
Format  函数用法_第4页
Format  函数用法_第5页
资源描述:

《Format 函数用法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、格式化数值结果表字符说明示例输出C货币string.Format("{0:C3}",2)$2.000D十进制string.Format("{0:D3}",2)002E科学计数法1.20E+0011.20E+001G常规string.Format("{0:G}",2)2N用分号隔开的数字string.Format("{0:N}",250000)250,000.00X十六进制string.Format("{0:X000}",12)Cstring.Format("{0:000.000}",12.2)012.200StringsTherereallyisn'tanyformattingwithi

2、nastrong,beyondit'salignment.AlignmentworksforanyargumentbeingprintedinaString.Formatcall.SampleGeneratesString.Format("->{1,10}<-","Hello");->Hello<-String.Format("->{1,-10}<-","Hello");->Hello<-NumbersBasicnumberformattingspecifiers:SpecifierTypeFormatOutput(PassedDouble1.42)Output(PassedInt-12

3、400)cCurrency{0:c}$1.42-$12,400dDecimal(Wholenumber){0:d}System.FormatException-12400eScientific{0:e}1.420000e+000-1.240000e+004fFixedpoint{0:f}1.42-12400.00gGeneral{0:g}1.42-12400nNumberwithcommasforthousands{0:n}1.42-12,400rRoundtrippable{0:r}1.42System.FormatExceptionxHexadecimal{0:x4}System.c

4、f90FormatExceptionCustomnumberformatting:SpecifierTypeExampleOutput(PassedDouble1500.42)Note0Zeroplaceholder{0:00.0000}1500.4200Padswithzeroes.#Digitplaceholder{0:(#).##}(1500).42 .Decimalpoint{0:0.0}1500.4 ,Thousandseparator{0:0,0}1,500Mustbebetweentwozeroes.,.Numberscaling{0:0,.}2Commaadjacentt

5、oPeriodscalesby1000.%Percent{0:0%}150042%Multipliesby100,adds%sign.eExponentplaceholder{0:00e+0}15e+2Manyexponentformatsavailable.;Groupseparatorseebelow  Thegroupseparatorisespeciallyusefulforformattingcurrencyvalueswhichrequirethatnegativevaluesbeenclosedinparentheses.Thiscurrencyformattingexam

6、pleatthebottomofthisdocumentmakesitobvious:DatesNotethatdateformattingisespeciallydependantonthesystem'sregionalsettings;theexamplestringsherearefrommylocallocale.SpecifierTypeExample(PassedSystem.DateTime.Now)dShortdate10/12/2002DLongdateDecember10,2002tShorttime10:11PMTLongtime10:11:29PMfFullda

7、te&timeDecember10,200210:11PMFFulldate&time(long)December10,200210:11:29PMgDefaultdate&time10/12/200210:11PMGDefaultdate&time(long)10/12/200210:11:29PMMMonthdaypatternDecember10rRFC1123datestringTue,10Dec200222:11:29GM

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。