I have Article
model which has property SellPrice
. I want wherever I use it to be displayed with 2
numbers after the decimal separator. It always has value of 2
numbers after the decimal separator but when the price
is for example 2,30
it's displayed as 2,3
and I want to be displayed as 2,30
. The same thing happens for property Quantity
in the same Article
model I want it to be displayed with 3 numbers after the decimal separator for example if its value is 1,1
to be displayed as 1,100
. For SellPrice
I tried the following:
[Column("sell_price")]
[XmlElement(ElementName = "sell_price", Namespace = "http://tempuri.org/DataSet1.xsd")]
[DisplayFormat(DataFormatString = "{0:C}")]
public decimal SellPrice { get; set; }
But DisplayFormat
is underlined with red and I'm not allowed to import its namespace using System.ComponentModel.DataAnnotations
. I guess it's deprecated. For displaying 3
numbers after decimal separator I didn't find even something deprecated. I found a lot of ways to do it using String.Format
but I use SellPrice
and Quantity
in a lot of places in my project and I don't want every time when I use the model properties to write String.Format
...... Is there any way to specify that in the model as attribute for example?