0

我创建了一个类

public class XYZ: DomainObject
{   
    public decimal Price { get; set; }
    public decimal Commission { get; set; }
}

现在我Price在很多地方使用财产。我要求将我的价格值更改54545,454.00.

所以我用这个

@String.Format("{0:N}", Model.Price)

但是在这种方法中,我必须在很多地方做以上事情,我想Price在我的课堂上用我的财产做一些事情。因此,当有人试图获得此属性时。他得到格式化的值5,454.00

我应该怎么办 ?

4

2 回答 2

6

您的属性是 a decimal,因此没有为其分配格式。您可以在此处添加另一个属性string并隐藏格式:

public class XYZ: DomainObject
{   
    public decimal Price { get; set; }

    public string PriceString
    {
        get { return Price.ToString("N"); }
    }

    public decimal Commission { get; set; }
}
于 2013-07-09T06:53:56.333 回答
0

那么这样的事情呢:

public string PriceFormatted { get { return string.Format("{0:N}", Price); } }
于 2013-07-09T06:54:57.527 回答