十进制格式为百分比值? [英] Format decimal for percentage values?

查看:132
本文介绍了十进制格式为百分比值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想是这样的:

 的String.Format(值:{0:%%},0.8526)

在哪里%%是格式提供程序或任何我期待的。
应导致:值:%85.26

基本上,我需要它为WPF约束力,但首先让我们解决了一般格式问题:

 < TextBlock的文本={结合百分比,的StringFormat = %%}/>


解决方案

使用 P 格式字符串。这将通过文化而异:

 的String.Format(值:{0:P2},0.8526)//格式为85.26%(按文化而异)

What I want is something like this:

String.Format("Value: {0:%%}.", 0.8526)

Where %% is that format provider or whatever I am looking for. Should result: Value: %85.26..

I basically need it for wpf binding, but first let's solve the general formatting issue:

<TextBlock Text="{Binding Percent, StringFormat=%%}" />

解决方案

Use the P format string. This will vary by culture:

String.Format("Value: {0:P2}.", 0.8526) // formats as 85.26 % (varies by culture)

这篇关于十进制格式为百分比值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆