[英]I have a Data Table in which i have a column with decimal values
I have a Data Table with a column of decimal values. 我有一个带有十进制值列的数据表。 I should bind it to a drop down list where the drop down list should display the values of that decimal values in percentage without "%" symbol.I tried the following code in C#. 我应该将其绑定到一个下拉列表,该下拉列表应以百分比形式显示该十进制值的值,且不带“%”符号。我在C#中尝试了以下代码。
DropDownList1.DataTextFormatString = "{0:0%}";
0.981 is displayed as 98% in DropDown list , how should I write it to avoid % symbol such that only 98 will get displayed. 0.981在DropDown列表中显示为98%,应如何写以避免%符号,以便仅显示98。
The "%"
custom specifier multiples your value with 100
and uses PercentSymbol
of your CurrentCulture
. "%"
自定义说明符将您的值PercentSymbol
100
并使用CurrentCulture
PercentSymbol
。 That means your CurrentCulture
has %
as a PercentSymbol
and this custom speficier has to use it. 这意味着您的CurrentCulture
具有%
作为PercentSymbol
并且此自定义功能需要使用它。
As a solution, you can Clone
your CurrentCulture
and set PercentSymbol
to empty string and you can use that culture for your Thread.CurrentThread.CurrentCulture
and Thread.CurrentThread.CurrentUICulture
properties. 作为解决方案,您可以Clone
CurrentCulture
并将PercentSymbol
设置为空字符串,并且可以将该文化用于Thread.CurrentThread.CurrentCulture
和Thread.CurrentThread.CurrentUICulture
属性。
var clone = (CultureInfo)CultureInfo.InvariantCulture.Clone();
clone.NumberFormat.PercentSymbol = "";
Thread.CurrentThread.CurrentCulture = clone;
Thread.CurrentThread.CurrentUICulture = clone;
now when you do that DropDownList1.DataTextFormatString = "{0:0%}";
现在,当您执行该操作时, DropDownList1.DataTextFormatString = "{0:0%}";
, you will get 98
not 98%
,您将获得98
而不是98%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.