- 热门文章:
- · Numeric Parse Method
- · 日期和时间的转换
- · 自定义的转换格式
- · 如何将powerpoint转换为html
- · css设定表格宽度
- · .Net边学边讲(三)
- · Calling a Button Event from a Compiled DLL
- · datagrid怎么设置分页?
- · .NET之ASP Web Application快速入门(3)(转载)
- · .NET之ASP WebApplication快速入门(4)(转载)
- · .NET之ASP WebApplication快速入门(5)(转载)
- · .NET之ASP Web Application快速入门(1)(转载)
数值变换时的格式化字符举例
Standard Numeric Format Strings are used to return commonly used numeric string types. They take the form X0, where X is the format specifier and 0 is the precision specifier. The format specifier can be one of the seven built-in format characters that define the most commonly used .NET Framework numeric format types. The precision specifier controls the number of significant digits or zeros to the right of a decimal.
Format character Description Default return format (without precision specifier)
C or c Currency format $XX,XX.XX
($XX,XXX.XX)
D or d Decimal format [-]XXXXXXX
E or e Scientific (exponential) format [-]X.XXXXXXE+xxx
[-]X.XXXXXXe+xxx
[-]X.XXXXXXE-xxx
[-]X.XXXXXXe-xxx
F or f Fixed-point format [-]XXXXXXX.XX
G or g General format Variable. Either general or scientific.
N or n Number format [-]XX,XXX.XX
X or x Hexadecimal format Variable. Returns the minimum hexadecimal representation.
Currency Format
The "C" format specifier causes the Format method to return a string representing the number as a currency value. The currency symbols used (currency symbol, decimal separator, group separator, and so on) are determined by the current culture if a NumberFormatInfo object is not provided. An integer following the "C" determines the number of decimal places that are displayed. If no number is provided, two digits are shown after the decimal separator.
[C#]
int MyInt = 12345;
MyInt.format( "c", null );
// Returns the currency string "$12,345.00"
MyInt.format( "c3", null );
// Returns the exponential string "$12,345.000"
Decimal Format
The "D" format specifier converts the value from an integer to a base 10 (decimal) number. Only integral types support the "D" format code. A negative symbol is prefixed to the result if the value is negative. You can also specify the minimum number of decimal digits to display using a precision specifier.
[C#]
int MyInt = 123;
MyInt.format( "d5", null );
// Returns the decimal string "00123"
MyInt.format( "d2", null );
// Returns the decimal string "123"
Exponential Format
The “E” format specifier causes the Format method to return a string formatted as a scientific (or exponential) number. The precision specifier determines the number of digits after the decimal point. The case of the exponent format character ("E" or "e") determines the case of the exponent symbol.
[C#]
int MyInt = 12345;
MyInt.format( "e", null );
// Returns the exponential string "1.234500e+004"
MyInt.format( "e3", null );
// Returns the exponential string "1.235e+004"
Fixed Point Format
The "F" format specifier inserts a decimal to the right of a nondecimal number followed by the number of zeros specified by the precision specifier. If no precision specifier is supplied, two zeros will be inserted.
[C#]
int MyInt = 12345;
MyInt.format( "f", null );
// Returns the exponential string "12345.00"
MyInt.format( "f3", null );
// Returns the exponential string "12345.000"
General Format
The "G" format specifier converts a numeric value to either fixed point ("F") or scientific format ("E"). This specifier returns the most compact string representation for a given number.
[C#]
int MyInt = 12345;
MyInt.format( "g", null );
// Returns the exponential string "12345"
MyInt.format( "g3", null );
// Returns the exponential string "123e4"
Number Format
The "N" format specifier converts a numeric value to the form "[-]d,ddd,ddd.dd". A decimal is inserted at the far right of the number followed by the number of zeros specified by the format specifier. If no precision specifier is supplied, two zeros are inserted.
[C#]
int MyInt = 12345;
MyInt.format( "n", null );
// Returns the exponential string "12,345.00"
MyInt.format( "n3", null );
// Returns the exponential string "12,345.000"
Hexadecimal Format
The "X" format specifier converts a numeric value to a hexadecimal (base 16) string representation. The precision specifier determines the minimum number of digits returned. If no precision specifier is supplied, the minimum number of digits needed to represent the value is returned; otherwise, the number will be padded with zeros to meet the number of digits required by the precision specifier.
[C#]
int MyInt = 12345;
MyInt.format( "x", null );
// Returns the exponential string "3039"
MyInt.format( "x3", null );
// Returns the exponential string "3039"
下一篇:Numeric Parse Method >>
相关文章:
- · .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
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--9
