上一篇:.net里面的数值格式变换 >>
Picture Numeric Format Strings(我很难解释大家自己看)
If the built-in formatting strings do not provide the type of formatting you require, you can use picture format strings to create custom string output. Picture format strings contain a number of format characters that arrange the output of the Format method in almost any way imaginable.
Picture number format definitions are described using placeholder strings that identify the minimum and maximum number of digits used, the placement or appearance of the negative sign, and the appearance of any other text within the number.
The following table lists the picture formatting characters.
Format character Description Description
0 Display zero placeholder Results in a non-significant zero if a number has fewer digits than there are zeros in the format.
# Display digit placeholder Replaces the "#" symbol with only significant digits.
. Decimal point Displays a "." character.
, Group separator
multiplier
Separates number groups; for example, "1,000".
% Percent notation Displays a "%" character.
E+0
E-0
e+0
e-0
Exponent notation Formats the output of exponent notation.
\ Literal character Used with traditional formatting sequences like "\n" (newline).
@#ABC@#
"ABC"
Literal string Displays any string within quotes or apostrophes literally.
; Section separator Specifies different output if the numeric value to be formatted is positive, negative, or zero.
The following code is an example of picture number formatting.
[C#]
Double MyDouble = 12.345;
MyDouble. Format( "000.##", null );
// returns the string "012.35"
Double MyDouble = 5.14129
Int32 MyInt = 42
MyDouble.Format( "0###.##", null )
//Results in "0005.14"
MyDouble.Format( "%#.##", null )
//Results in "%514.13"
MyInt.Format( "My Number = #", null )
//Results in "My Number = 42"
MyInt.Format( "My Number \n= #", null )
//Results in "My Number
// = 42"
Picture formatting strings can be broken into three sections. If only one section is defined, all numbers will be formatted as specified in that section. If two sections are defined, the first section will be applied to positive and zero values while the second section will be applied to negative numbers. If three sections are defined, the first applies to positive values, the second applies to negative values, and the third applies to values of zero. For example:
[C#]
int MyPosInt = 42, MyNegInt = -42, MyZeroInt = 0;
MyPosInt.Format( "Positive Number = #; Negative Number = #; Zero Value = #", null )
//Results in "Positive Number = 42"
MyNegInt.Format( "Positive Number = #; Negative Number = #; Zero Value = #", null )
//Results in "Negative Number = -42"
MyZeroInt.Format( "Positive Number = #; Negative Number = #; Zero Value = #", null )
//Results in "Zero Value = 0"
下一篇:数值变换时的格式化字符举例 >>
相关文章:
- · .NET之ASP Web Application快速入门(1)(转载)
- · .NET之ASP Web Application快速入门(2) (转载)
- · ASP.NET中的错误处理支持
- · ASP.NET中的代码分离
- · 在ASP.NET中使用AdRotator控件(转)
- · 在ASP.NET中动态生成图形(转)
- · 用ASP.NET加密口令(转)
- · ASP.NET中的错误处理支持(转)
- · ASP.NET中发送Email完整实例(转)
- · ASP.NET中的注释符号
- · 老外编的程序(八):在CSharp里面使用Http Get方法
- · 显示当前浏览器头信息(HEADER)
- · 轮换广告
- · 一个dnslookuo例子。。。
- · beta2的web.config配置
- · 如何在web.config中建立公用的的数据库连接
- · asp.net key considerations(三)
- · asp.net key considerations(二)
- · WebPoll in C#[Vs.net Bate2 等级:中 高]
- · Form code generator V1.1 by Steve Schofield[bate2 等级:中级](转载:aspfree)
- · asp.net key considerations(一)从前用惯了asp的朋友看看这个吧,大家常问的如Request等问题解答得很清楚
- · 使用DataList进行3层编历
- · part1: ShowIssueCat.aspx.cs
- · part2: ShowIssueCat.aspx
- · DataNavigateUrlFormatString的使用方法
- · ASP.NET XML/XSL Transforms(转载www.aspalliance.com)
- · Hiding/Manipulating Databound Items(转载www.aspalliance.com)
- · 无刷新的聊天室的制作兼谈组件制作和ClientSide Script(一)
- · 关于异常捕获
- · 无刷新的聊天室的制作兼谈组件制作和ClientSide Script(二)
- · 转贴:用ASP.NET结合XML制作广告管理程序
- · 转贴:用ASP.NET结合XML制作广告管理程序(2)
- · ASP.NET: Dynamically set Text and Value fields for a DropDownList
- · asp.net优化(二)
- · DotNet中定制自己的表格
- · 回答讨饭猫之asp.net优化(一)
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--8
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--7
