你好,我有一個Web應用程序的困難。我差不多已經完成了,但我正在解決這個問題。因此,通過這個Web應用程序,還有另一個頁面顯示來自用戶的銷售價格和折扣金額的輸入,然後從銷售價格 - 折扣金額中獲得總價格。我終於得到第二頁(代碼來自這裏)獲取會話字符串值,但我需要將這些正確格式化爲貨幣。我從註釋部分的第一頁複製了代碼,嘗試分析它的代碼,但是我很茫然,因爲我差不多完成了,所以我會很感激這些幫助。從C中的字符串會話格式化貨幣#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Confirm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//int salesPrice, discountAmount, totalPrice;
UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
if (Session["salesprice"] != null && Session["discountamount"] != null && Session["totalprice"] != null)
{
lblSalesPrice.Text = Session["salesprice"].ToString();
lblDiscountAmount.Text = Session["discountamount"].ToString();
lblTotalPrice.Text = Session["totalprice"].ToString();
/*
decimal salesPrice = Convert.ToDecimal(txtSalesPrice.Text);
decimal discountPercent = Convert.ToDecimal(txtDiscountPercent.Text)/100;
decimal discountAmount = salesPrice * discountPercent;
decimal totalPrice = salesPrice - discountAmount;
lblDiscountAmount.Text = discountAmount.ToString("c");
lblTotalPrice.Text = totalPrice.ToString("c");*/
}
}
protected void Button1_Click(object sender, EventArgs e)
{
lblMessage.Text = "This function hasn't been implemented yet.";
}
protected void Button2_Click(object sender, EventArgs e)
{
Server.Transfer("Default.aspx");
}
}
我一定會錯過一些東西,因爲我不太明白你有什麼問題或最終目標是什麼。你問如何將字符串轉換爲貨幣或完全不同的東西? –
這就是我所要求的。我現在已經正常工作了。 – iuliko