在視圖中,
PAYMENT1 = 1,200.50
PAYMENT2 = 1,500.50如何顯示字符串格式的變量?
totalpayment = 2701
我希望totalpayment具有與逗號的格式。
totalpayment = 2,701.00
我嘗試使用.ToString
,但沒有奏效。任何想法?
public ActionResult Edit(int id, bool update = false)
{
TBL_PROJ project = db.TBL_PROJ.Find(id);
ViewBag.PAYMENT1 = Convert.ToDecimal(project.PAYMENT1).ToString("#,##0.00");
ViewBag.PAYMENT2 = Convert.ToDecimal(project.PAYMENT2).ToString("#,##0.00");
var totalPayment = project.PAYMENT1 + project.PAYMENT2;
project.TotalPayment = (float)Math.Round(totalPayment, 2); //This Part
return View(project);
}
var不適用於字符串,您需要使用convert.tostring(),然後在該字符串上應用格式 –