本文介绍了如何关闭百分号在.NET / WPF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的WPF应用程序,以显示所有百分比,但不能%符号。例如20%的人会被显示为20,但我仍想使用标准格式的百分比(所以我得到的字符串格式化的利益100对我来说,乘以它)

I would like my WPF application to display all percentages without % sign. For example 20% would be displayed as "20" but i still want to use the standard formatting for percentages (so i get the benefit of string formatter to multiply it by 100 for me)

换句话说,我怎么的String.Format(0.00%,0.2)来输出20,而不是20%?

in other words, how do i getstring.Format("0.00%", 0.2) to output "20" but not "20%"?

是否有可能在全球范围内定义PercentSymbol作为整个应用程序?

Is it possible to globally define PercentSymbol as empty string for the entire application?

在特定的我用我的WPF应用程序ContentStringFormat格式化数字和百分比。也许我可以直接在WPF做到这一点。

In particular i am using ContentStringFormat in my WPF application to format the numbers and percentages. Maybe i can do it directly in WPF.

推荐答案

提供自己的的NumberFormatInfo 的String.Format 。基于固定区域性的例子:

Provide your own NumberFormatInfo to String.Format. Example based on the invariant culture:

NumberFormatInfo info = (NumberFormatInfo) CultureInfo.CurrentCulture.NumberFormat.Clone();
info.PercentSymbol = String.Empty;
string s = String.Format(info, "{0:00%}", 0.02);

这篇关于如何关闭百分号在.NET / WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 02:40