Format a decimal in a view

dont do in DisplayFor... in the class set the atributte like this one.

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:N2}")]
    public virtual decimal Valor
    {
        get;
        set;
    }

I wouldn't do this inside the view. It would be better to centralize this and provide this information as metadata as below:

public class Foo { 

    [DisplayFormat(DataFormatString = "{0:n0}")]
    public decimal Bar { get; set; }
}

Then use this as usual:

@Html.DisplayFor(m => m.Bar)

Do you need to use Html.DisplayFor?

Otherwise you can just do:

@String.Format("{0:n0}",currentItem.QualityM1)

Tags:

Asp.Net Mvc