【发布时间】:2013-06-14 13:22:05
【问题描述】:
当我将此对象作为 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)?
【问题讨论】:
-
为什么?小数位仅在呈现给用户时才重要。
-
它四舍五入到小数点后 2 位,但仍以
double的形式存储,根据定义,它还有更多小数位。正如 Henk 所说,您需要使用 JavaScript 呈现任何您喜欢的内容。 -
@ElRonnoco 我将其存储为字符串(
adjustment是字符串,而s.adjustment是双精度) -
@HenkHolterman 我将它作为字符串传递,而不是双精度。所以,这里的演示很重要。
-
@GrantWinney
s.adjustment是?double(可选双精度)。但是,adjustment是string。
标签: c# json linq linq-to-sql asp.net-mvc-4