Format 函数用法.docx

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Format 函数用法

格式化数值结果表字符说明示例输出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.200StringsThere really isnt any formatting within a strong, beyond its alignment. Alignment works for any argument being printed in a String.Format call. SampleGeneratesString.Format(-{1,10}-, Hello);- Hello-String.Format(-{1,-10}-, Hello);-Hello -NumbersBasic number formatting specifiers:SpecifierTypeFormat Output (Passed Double 1.42)Output (Passed Int -12400)cCurrency{0:c}$1.42-$12,400dDecimal (Whole number){0:d}System.FormatException-12400eScientific{0:e}1.420000e+000-1.240000e+004fFixed point{0:f}1.42-12400.00gGeneral{0:g}1.42-12400nNumber with commas for thousands{0:n}1.42-12,400rRound trippable{0:r}1.42System.FormatExceptionxHexadecimal{0:x4}System.FormatExceptioncf90Custom number formatting:SpecifierTypeExample Output (Passed Double 1500.42)Note0Zero placeholder{0:00.0000}1500.4200Pads with zeroes.#Digit placeholder{0:(#).##}(1500).42?.Decimal point{0:0.0}1500.4?,Thousand separator{0:0,0}1,500Must be between two zeroes.,.Number scaling{0:0,.}2Comma adjacent to Period scales by 1000.%Percent{0:0%}150042%Multiplies by 100, adds % sign.eExponent placeholder{0:00e+0}15e+2Many exponent formats 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 especially dependant on the systems 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 PMFFull date time (long)December 10, 2002 10:11:29 PMgDefault date t

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档