我创建了一个类
public class XYZ: DomainObject
{
public decimal Price { get; set; }
public decimal Commission { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在我Price在许多地方使用财产.我要求将价格值更改5454为5,454.00.
所以我用这个
@String.Format("{0:N}", Model.Price)
Run Code Online (Sandbox Code Playgroud)
但是在这种方法中,我必须在很多地方做上面的事情,我想Price在我班里的房产里做点什么.所以当一个人试图获得这个属性时.他获得格式化的值5,454.00.
我该怎么办 ?
您的属性是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; }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1001 次 |
| 最近记录: |