【发布时间】:2014-03-04 09:44:40
【问题描述】:
我在数据集中有一列 AMOUNT_PAISE。我正在从来自 sql server 存储过程的结果集中绑定这个数据集。对于 DB 货币中的 AMOUNT_PAISE 列是派斯(假设特定行为 888 派斯),但我想以卢比显示这个金额(卢比等值 888 派斯是 8.88)。但我不能直接分配它,因为数据集包含 int64 值。当我将十进制 888 转换为 int64 时,它给出 9(888/100 = 8.88,当转换为 int64 时,它给出 9) 所以请告诉我现在应该尝试什么。
从派斯转换为卢比的公式。
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;
}
}
这是 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>
【问题讨论】:
标签: c# sql-server gridview dataset