简体   繁体   English

我有一个数据表,其中有一个带有十进制值的列

[英]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.CurrentCultureThread.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.

相关问题 如何过滤表格并选择ID列中具有父项的行 - How can I filter table and select rows which have parentid in id column 我无法更改没有偏移量的地址值 - I can t change values of addresses which doesnt have offset 是否可以创建一个字典,其中的值可以具有多种数据类型? (另外我如何遍历一个数组作为我的值之一) - Is it possible to create a dictionary in which values can have multiple data types? (Also how do I iterate through an array as one of my values) XamDataGrid:我有两列(显示十进制数据):我想要一列带有“ $”符号,另一列没有。 怎么样? - XamDataGrid: I have two columns (displaying decimal data): I want one with a “$” sign, and one without. How? 我有一个表,该表具有由三列组成的主键。 如何索引此表? - I have a table which has a primary key that is made of three columns. How do I index this table? 我可以在gridview中有一个用于数据输入的DisplayName和列标题吗? - Can I have one DisplayName for data entry and the Column Headers in a gridview? 如何将对数据表所做的更改提交到从中获取的表中? - How do I commit the changes I have made to a DataTable to the Table from which I grabbed it? 如何计算数据库中具有3个不同值的列中的数据并将其显示在Graph中? - How to count data from a column in database which will have 3 different values and display it in Graph? 我必须将数据插入非规范化表中的什么选项 - What option do I have to insert data into a denormalized table 如何让Decimal.TryParse解析0.0? - How can I have Decimal.TryParse parse 0.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM