C# 如何将Json数组设置为货币?
我需要把这个197000.99996换成这个197001美元 我知道我需要使用{0:C} 但我不知道在使用数组时如何做到这一点,下面是代码C# 如何将Json数组设置为货币?,c#,asp.net-mvc-3,money-format,C#,Asp.net Mvc 3,Money Format,我需要把这个197000.99996换成这个197001美元 我知道我需要使用{0:C} 但我不知道在使用数组时如何做到这一点,下面是代码 public ActionResult getAjaxSCs(string PA = null, float AmountList = 0) { if (PA != null) { var SCList = from x in db.NDE_Actuals_W
public ActionResult getAjaxSCs(string PA = null, float AmountList = 0)
{
if (PA != null)
{
var SCList = from x in db.NDE_Actuals_Web
where x.PA == PA
group x by new { x.SPEND_CATEGORY, x.ACCOUNTING_PERIOD} into scgroup
select new { spend_category = scgroup.Key.SPEND_CATEGORY, accounting_period = scgroup.Key.ACCOUNTING_PERIOD, amount = scgroup.Sum(x=> x.Amount)};
SCList = SCList.OrderBy(x => x.spend_category);
Dictionary<string, double[]> SCRow = new Dictionary<string, double[]>();
double[] SCContent = new double[12];
string lastSpendCategory = null;
foreach (var item in SCList)
{
if (lastSpendCategory != item.spend_category)
{
SCContent = new double[12];
}
int accounting_period = int.Parse(item.accounting_period) -1;
SCContent[accounting_period] = (double)item.amount;
SCRow[item.spend_category] = SCContent;
lastSpendCategory = item.spend_category;
}
return Json(SCRow, JsonRequestBehavior.AllowGet);
}
return View();
}
public ActionResult getAjaxSCs(string PA=null,float AmountList=0)
{
如果(PA!=null)
{
var SCList=从x到db.NDE\u实际值\u Web
其中x.PA==PA
按新的{x.Expense_CATEGORY,x.ACCOUNTING_PERIOD}将x组放入scgroup
选择新的{支出类别=scgroup.Key.支出类别,会计期间=scgroup.Key.accounting期间,金额=scgroup.Sum(x=>x.amount)};
SCList=SCList.OrderBy(x=>x.expense\u类别);
字典SCRow=新字典();
double[]SCContent=新的double[12];
字符串lastSpendCategory=null;
foreach(SCList中的变量项)
{
if(lastSpendCategory!=项目花费\u类别)
{
SCContent=新的双精度[12];
}
int accounting_period=int.Parse(item.accounting_period)-1;
SCContent[会计期间]=(双)项目金额;
SCRow[项目支出\类别]=SCContent;
lastSpendCategory=item.spend\u类别;
}
返回Json(SCRow,JsonRequestBehavior.AllowGet);
}
返回视图();
}
我需要转换SCRow,这样它将发送货币格式的值,并舍入小数。谢谢你的帮助 无论何时处理货币,请始终使用
decimal
,切勿使用double
。我无权访问数据库来更改变量类型。如果我能通过代码转换它,尽管我洗耳恭听!