当我将此对象作为 JSON 传回时,它看起来像这样:
0.000000000000000e+000
我在 C# 中的代码是:
// get adjustments for user
IEnumerable<Severity> existingSeverities =
from s in db.AdjusterPricingGrossLossSeverities
where s.type == type
&& s.adjusterID == adj.id
select new Severity
{
id = s.severity,
adjustment = Math.Round((double)s.adjustment, 2, MidpointRounding.AwayFromZero).ToString(),
isT_E = (bool)s.isTimeAndExpense
};
我怎样才能让它四舍五入到小数点后两位 (0.00)?
最佳答案
使用;
dec.ToString("#.##");
参见 this answer了解更多信息
如果它是 Console
应用程序中的可空 double 值;
double ? d = 2.22222;
Console.WriteLine(d.Value.ToString("#.##"));
关于C# 不四舍五入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17109514/