[英]How to set Decimal Value in a Dataset in C#?
I have a Column AMOUNT_PAISE in Dataset. 我在数据集中有一个AMOUNT_PAISE列。 I'm binding this dataset from the result set coming from sql server stored procedure.
我从SQL Server存储过程的结果集中绑定了此数据集。 for AMOUNT_PAISE column in DB currency is in paise(lets say 888 paise for a particular row) but I want to display this amount in Rupees(Rupee equivalenof 888 paise is 8.88).
DB货币中AMOUNT_PAISE列的汇率为派伊(对于特定行说888派伊),但我想以卢比显示此金额(888卢比的当量为8.88)。 But I can not directly assign it, because dataset contains int64 values.
但是我不能直接分配它,因为数据集包含int64值。 when I convert decimal 888 to int64 it gives 9 (888/100 = 8.88 and when converted to int64 it gives 9) So Please tell me what should I try now.
当我将十进制888转换为int64时,它给出9(888/100 = 8.88,而当转换为int64时,它给出9)。所以请告诉我现在我应该尝试什么。
formula to convert from paise to rupee. 从帕兹转换为卢比的公式。
rupee = paise/ 100; //upto 2 decimal points
if (dsTransactionLogs.Tables.Count > 0)
{
if (dsTransactionLogs.Tables[0].Rows.Count > 0)
{
//Code to convert amount from Paise to Rs.
int i = 0;
foreach (DataRow row in dsTransactionLogs.Tables[0].Rows)
{
decimal decimalAmountInPaise = Convert.ToDecimal(dsTransactionLogs.Tables[0].Rows[i]["AMOUNT_PAISE"]);
decimalAmountInPaise = Math.Round(decimalAmountInPaise / 100, 2);
//Int64 int64AmountInPaise = Convert.ToInt64(decimalAmountInPaise);
string strAmount = decimalAmountInPaise.ToString("#.##");
dsTransactionLogs.Tables[0].Rows[i]["AMOUNT_PAISE"] = Convert.ToInt64(strAmount);
i++;
}
GridViewTRANSACTIONDETAILS.DataSource = dsTransactionLogs;
GridViewTRANSACTIONDETAILS.DataBind();
transactionGVDiv.Style.Add("height", "400px");
//LabelNoTransactionLogsID.Visible = false;
}
else
{
//LabelNoTransactionLogsID.Visible = true;
}
}
this is aspx code for this column in gridview. 这是gridview中此列的aspx代码。
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Amount">
<ItemTemplate>
<asp:Label runat="server" ID="AmountLbl" NavigateUrl="#" Text='<%#Eval("AMOUNT_PAISE") %>'> ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Just Change you line : 只需更改您的行:
dsTransactionLogs.Tables[0].Rows[i]["AMOUNT_PAISE"] = Convert.ToInt64(strAmount);
to 至
dsTransactionLogs.Tables[0].Rows[i]["AMOUNT_PAISE"] = strAmount;
I suggest you do the conversion when displaying, rather than attempting to modify the DataTable. 我建议您在显示时进行转换,而不要尝试修改DataTable。 Ie replace:
即替换:
... Text='<%#Eval("AMOUNT_PAISE") %>'> ...
by something like: 通过类似:
... Text='<%# (Convert.ToDecimal(Eval("AMOUNT_PAISE")) / 100M).ToString("N2") %>'> ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.