用逗号分隔数字为数千个asp.net [英] Separate number with comma for thousands asp.net
问题描述
我一直在尝试以下几行(单独使用) )在后端(没有任何工作,他们只是切断小数)
row [Applied_Amount_Varience_Sum] = string.Format ({0:#,### 0},Convert.ToDecimal(row [Applied_Amount_Varience_Sum]));
row [Applied_Amount_Varience_Sum] = Convert.ToDecimal(row [Applied_Amount_Varience_Sum])。ToString(#,## 0.00);
row [Applied_Amount_Varience_Sum] = String.Format({0:n},Convert.ToDecimal(row [Applied_Amount_Varience_Sum]));
row [Applied_Amount_Varience_Sum] = Convert.ToDecimal(row [Applied_Amount_Varience_Sum])。ToString(N0);
行是对数据库中表的引用(我正在循环每个返回并经过的对象行)
我把这个地方绑定到gridview。所以基本上我在绑定之前将这些属性改为逗号,但它不会这样做
我试过的这些行会改变这个
1092.00
到这个
1092
但我正在努力达到这个目标
1,092
*编辑*
这是在一个模板字段内(因为我需要它是一个带有onclick函数的链接)
< ItemTemplate>
< asp:LinkButton ID>
< asp:TemplateField ItemStyle-HorizontalAlign =CenterHeaderText =Applied Amount Variance =LbPathrunat =server
Text ='<%#Eval(Applied_Amount_Varience_Sum)%>'
CommandName =BindExpand
OnCommand =BindExpand
CommandArgument ='<%#Bind(Applied_Amount_Varience_Sum)%>'>
< / asp:LinkButton>
< / ItemTemplate>
< / asp:TemplateField>
如果您正在寻找货币使用
DataFormatString ={0:c}
否则使用
DataFormatString ={0:N2}
尝试
Text =' <%#Eval(Applied_Amount_Varience_Sum,{0:c})%>'
或
Text ='<%#Eval(Applied_Amount_Varience_Sum,{0:N2})%> '
How do you do separate numbers with commas for every thousand on asp.net gridview (with c# in the back)
I have been trying the following lines (individually) in the backend(nothing works, they just cut off the decimal places)
row["Applied_Amount_Varience_Sum"] = string.Format("{0:#,###0}", Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]));
row["Applied_Amount_Varience_Sum"] = Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]).ToString("#,##0.00");
row["Applied_Amount_Varience_Sum"] = String.Format("{0:n}", Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]));
row["Applied_Amount_Varience_Sum"] = Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]).ToString("N0");
row is a reference to the table in the database (I am looping through each object returned and going through the rows)
I have putting this where I bind to the gridview. So basically I right before it binds I change those attributes to have a comma but it doesn't do that
The lines I tried will change this
1092.00
to this
1092
but I am trying to achieve this
1,092
* EDIT *
This is within a template field (because I needed it to be a link with an onclick function
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Applied Amount Variance">
<ItemTemplate>
<asp:LinkButton ID="LbPath" runat="server"
Text='<%# Eval("Applied_Amount_Varience_Sum") %>'
CommandName="BindExpand"
OnCommand="BindExpand"
CommandArgument='<%#Bind("Applied_Amount_Varience_Sum") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
IF you are looking for Currency use
DataFormatString="{0:c}"
otherwise use
DataFormatString="{0:N2}"
Try
Text='<%# Eval("Applied_Amount_Varience_Sum","{0:c}") %>'
or
Text='<%# Eval("Applied_Amount_Varience_Sum","{0:N2}") %>'
这篇关于用逗号分隔数字为数千个asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!