WPF中StringFormat的用法
WPF中StringFormat的用法可以参照C#中string.Format的用法
1、
C#中用法:
格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元)示例:
string.Format("{0:C}",0.2) 结果为:¥0.10 (英文操作系统结果:$0.10)
默认格式化小数点后面保留两位小数,如果需要保留一位或者更多,可以指定位数
string.Format("{0:C1}",10.05) 结果为:¥10.1 (截取会自动四舍五入)
格式化多个Object实例 string.Format("会员价:{0:C},优惠价{1:C}",99.15,109.25)
WPF中用法:
格式化货币示例:
<TextBox Name="txtPrice" HorizontalAlignment="Left" Width="170" Height="24" VerticalAlignment="Top" Background="White">
<TextBox.Text>
<Binding Path="Price" StringFormat="{}{0:C}"/>
</TextBox.Text>
</TextBox>
2、
C#中用法:
格式化十进制的数字(格式化成固定的位数,位数不能少于未格式化前,只支持整形)示例:
string.Format("{0:D3}",99) 结果为:099
string.Format("{0:D2}",1234) 结果为:1234,(精度说明符指示结果字符串中所需的最少数字个数。)
WPF中用法:
格式化十进制的数字示例:
<TextBox Name="txtRoomCount" HorizontalAlignment="Left" Width="170" Height="24" VerticalAlignment="Top" Background="White">
<TextBox.Text>
<Binding Path="RoomCount" StringFormat="{}{0:D2}"/>
</TextBox.Text>
</TextBox>
3、
C#中用法:
用分号隔开的数字,并指定小数点后的位数示例:
string.Format("{0:N}", 12300) 结果为:12,300.00 (默认为小数点后面两位)
string.Format("{0:N3}", 12300.1234) 结果为:12,300.123(自动四舍五入)
WPF中用法:
同格式化十进制的数字示例
4、
C#中用法:
格式化百分比示例:
string.Format("{0:P}", 0.12341) 结果为:12.34% (默认保留百分的两位小数)
string.Format("{0:P1}", 0.1256) 结果为:12.6% (自动四舍五入)
WPF中用法:
同格式化十进制的数字示例
5、
C#中用法:
零占位符和数字占位符示例:
string.Format("{0:0000.00}", 12345.015) 结果为:12345.02
string.Format("{0:0000.00}", 123.015) 结果为:0123.02
string.Format("{0:###.##}", 12345.015) 结果为:12345.02
string.Format("{0:####.#}", 123.015) 结果为:123194
WPF中用法:
同格式化十进制的数字示例
6、
C#中用法:
日期格式化示例:
string.Format("{0:d}",System.DateTime.Now) 结果为:2010-6-19 (月份位置不是06)
string.Format("{0:D}",System.DateTime.Now) 结果为:2010年6月19日
string.Format("{0:f}",System.DateTime.Now) 结果为:2010年6月19日 20:30
string.Format("{0:F}",System.DateTime.Now) 结果为:2010年6月19日 20:30:10
string.Format("{0:g}",System.DateTime.Now) 结果为:2010-6-19 20:30
string.Format("{0:G}",System.DateTime.Now) 结果为:2010-6-19 20:30:10
string.Format("{0:m}",System.DateTime.Now) 结果为:6月19日
string.Format("{0:t}",System.DateTime.Now) 结果为:20:30
string.Format("{0:T}",System.DateTime.Now) 结果为:20:30:10
string.Format("{0:yyyy-MM-dd HH:mm}",System.DateTime.Now) 结果为:2010-6-19 20:30
string.Format("{0:yyyy-MM-dd }",System.DateTime.Now) 结果为:2010-6-19
WPF中用法:
日期格式化示例:
<TextBox Name="txtCreateTime" HorizontalAlignment="Left" Width="170" Height="24" VerticalAlignment="Top" Background="White">
<TextBox.Text>
<Binding Path="CreateTime" StringFormat="{}{0:yyyy-MM-dd HH:mm}"/>
</TextBox.Text>
</TextBox>

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
【c#】队列(Queue)和MSMQ(消息队列)的基础使用
原文: 【c#】队列(Queue)和MSMQ(消息队列)的基础使用 首先我们知道队列是先进先出的机制,所以在处理并发是个不错的选择。然后就写两个队列的简单应用。 Queue 命名空间 命名空间:System.Collections,不在这里做过多的理论解释,这个东西非常的好理解。 可以看下官方文档:https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.queue?view=netframework-4.7.2 示例代码 我这里就是为了方便记忆做了一个基本的例子,首先创建了QueueTest类: 包含了获取队列的数量,入队和出队的实现 1 public class QueueTest 2 { 3 public static Queue<string> q = new Queue<string>(); 4 5 #region 获取队列数量 6 public int GetCount() 7 { 8 9 return q.Count; 10 } 11 #endregion 12 13...
- 下一篇
解决ASP.NET中Redis 每小时6000次访问请求的问题
原文:解决ASP.NET中Redis 每小时6000次访问请求的问题 虽然ServiceStack v4是商业支持的产品,但我们也允许免费使用小型项目和评估目的。上面的NuGet包中包含可以使用许可证密钥解锁的配额: 10 ServiceStack中的操作(即请求DTO) OrmLite中的10个数据库表 PocoDynamo中的10个DynamoDB表 Redis客户端类型API中的20种不同类型 使用Redis客户端每小时6000个请求 C#利用ServiceStack.Redis来操作Redis,它是Redis官方推荐的C#客户端,性能非常优越,使用也很方便,但是有如下的问题: 每小时只能访问Redis 6000次 The free-quota limit on ‘6000 Redis requests per hour‘ has been reached. Please see https://servicestack.net to upgrade to a commercial license. 经过详细查询在ServiceStack的官网(https://servicest...
相关文章
文章评论
共有0条评论来说两句吧...