嗨,我在使用这种格式显示金额时遇到问题: 0,000.00 。我正在使用网格视图和数据阅读器来显示 mySQL 数据库中的金额,以 Decimal 作为我的数据类型,我的输出仅显示 0000.00
你能帮我解决这个问题吗?谢谢你。
private void DisplayOrderDetails(int nOrderNo)
{
OpenConnection();
SqlCommand cmdSelect = new SqlCommand();
cmdSelect.Connection = cn;
cmdSelect.CommandType = CommandType.Text;
cmdSelect.Transaction = trnOrder;
cmdSelect.CommandText =
"SELECT OrderDetailNo, OrderNo, PackagingOutside, Quantity, Unit, ProductNo, ProductName, " +
"ProductSize, PackagingInside, " +
"SellingDiscount1, SellingDiscount2, SellingDiscount3, SellingDiscount4, " +
"SellingPrice, Amount FROM OrderDetails WHERE OrderNo = '"
+ nOrderNo + "'";
SqlDataAdapter daDetail = new SqlDataAdapter();
daDetail.SelectCommand = cmdSelect;
DataSet ds = new DataSet();
daDetail.Fill(ds, "OrderDetails");
grdDetails.DataSource = null;
grdDetails.DataSource = ds.Tables["OrderDetails"];
DisplayTotal();
}
private void DisplayTotal()
{
double dTotal = 0;
//for encountering errors in the future
try
{
for (int nRow = 0;
nRow <= dsDetail.Tables["OrderDetails"].Rows.Count - 1;
nRow++)
{
dTotal = dTotal +
Convert.ToDouble(dsDetail.Tables["OrderDetails"].Rows[nRow]["Amount"].ToString());
}
}
catch //(Exception ex)
{
//MessageBox.Show(ex.Message);
}
lblTotal.Text = String.Format("{0:#,###,##0.00}", dTotal);
}