c# - Format number with two zeros after comma? -


i have property on model this:

[displayformat(dataformatstring = "{0:c2}")] public decimal totalprice { get; set; } 

when totalprice example 800,00 view shows $ 800,00 , if totalprice 800,01 (or that), view shows $ 800,01 , this correct client want's if totalprice contains decimals, view must show ,00 instead of decimals. can't format number [displayformat(dataformatstring = "{0:c0}")] because show $ 800 , don't want that. what's right formatting case?

to make example:

totalprice = 800 //output: $ 800,00 totalprice = 800.23 //output: $ 800,00 totalprice = 800.63 //output: $ 801,00 

[displayformat(dataformatstring = "{0:c2}")] public decimal totalprice {      ()     {return math.round(this.totalprice);}     set; 

}

or if need able decimals totalprice then

[displayformat(dataformatstring = "{0:c2}")] public decimal totalprice { get; set; }  [displayformat(dataformatstring = "{0:c2}")] public readonly decimal totalroundedprice {     ()     {return math.round(this.totalprice);} } 

Comments