首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 网络编程-> ASP.NET教程
.net里面的数值格式变换-.NET教程,Asp.Net开发
作者:网友供稿 点击:51
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
every .net framework base data type (int32, int64, single, double, and so on) contains a format method and a tostring method that return a string-formatted representation of the original value. the format method provides several formatting options and the ability to dynamically change output based on the current culture. the tostring method provides only one formatting option and is not influenced by the current culture.

the format method is useful if you want to convert one of the standard .net framework data types to some other format. for example, if you have an integer value of 100 that you want to represent to the user as a currency value, you could easily use the format method to produce a string of "$100.00". note that the original value contained in the data type is not converted, but a new string is created that represents the original value. this new string cannot be used for calculation until it is converted back to a .net base data type. the original value, however, can continue to be calculated at anytime.

the format method takes the following forms, where xxx is the name of the numeric base data-type:

  static xxx format(xxx value, string format);
  static xxx format(xxx value, string format,
                               numberformatinfo info);
  static xxx format(string format,
                iserviceobjectprovider s);
the format method takes a combination of three parameters: a value, a string format specifier, and an iserviceobjectprovider interface.

the iserviceobjectprovider flag is used to change the culture. it specifies characters to use for decimal and thousand separators and the spelling and placement of currency symbols. when set to null (in visual basic nothing), it will use the characters specified by the current culture.

two format strings are accepted by the format method: standard numeric format strings and picture numeric format strings. standard format strings are built-in options that address the most common formatting requirements, while picture strings are constructed by developers to address additional formatting requirements.

in following examples the format method displays the value of 100 as a currency-formatted string in the consoles output window:

[c#]
int myint = 100;
myint.format("c", null);
//returns "$100.00"
in this example, the format method takes two parameters: the format string and iserviceobjectprovider. the format string specifies the return value of the format method. in this case, the string has a value of "c", which specifies that the format method will return a currency representation of the original value. you can safely set the iserviceobjectprovider flag to null (nothing), specifying that the default current culture will be used. note that the format method returns a string data type, not a numeric data type.

the following example is similar to the previous example, except that the value is not retrieved from a previously declared int variable:

[c#]
int.format( 100, "c");
//returns "$100.00"
in this example, the value to be formatted is passed as the first parameter and the format string is passed as the second. the .net framework allows you to format any value without actually declaring and initializing it as a variable if you use the above syntax.

the tostring method quickly converts a .net framework base type value into a string. it requires no arguments and is easy to use. the following example converts an integer value of 42 into a string value:

int myint = 42;
string mystring =  myint.tostring();
//mystring will have a string value of "42"

文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·ASP.NET三层架构示例(中文版)-.NET教程,面向对象编程
·C#自定义控件制作篇-.NET教程,C#语言
·asp.net上传图片时,产生预览
·关于DataGrid 数据导入Excel乱码-ASP教程,数据库相关
·ado.net中数据库连接方式
·用asp.net(c#)连接oracle数据库的方法
·网页制作小技巧-ASP教程,ASP应用
·动态改变asp.net网页的标题
·asp.net中利用cookies保持客户端信息
·关于C#中switch语句的一点注意-.NET教程,C#语言
最新文章
·用vb.net 2005编写定时关机程序_vb/vb.net教程
·vb.net实现窗体图标最小化到状态栏_vb/vb.net教程
·如何提高google adsense单价:渠道篇_网赚技巧
·做百度主题推广的经验谈_网赚技巧
·解读电子商务规划关键词_站长心得
·手把手教你建立自己的网站_站长心得
·学网页设计与网页制作,你该做些什么?_站长心得
·写给新人的google排名知识_google推广
·google网络推广adwords帐户申请解析_google推广
·如何合理提高google adsense的收入_google推广
相关主题
  • .net里动态生成控件数组-.NET教程,组件控件开发
  • .NET里面的Interop太烂了-.NET教程,.NET Framework
  • .Net里的哈希表和串行化-.NET教程,评论及其它
  • .Net里的序列化-.NET教程,Asp.Net开发
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭