1

I have picked up an MVC solution and I am trying to format a double variable to 2 decimal places on a form table. In the modelview it is set using

[DisplayFormat(DataFormatString = "{0:F2}", ApplyFormatInEditMode = true)] 

before the public double declaration But this is not passed through to the table. The table is created using javascript.

I have tried to modify the variable in the javascript but that fails. here is an extract of the code used

<div class="row">
    <div class="col-md-3">Journey distance in miles</div>
    <div class="col-md-9">@Model.Miles</div>
</div>

The web page just displays the value without any formatting I am new to this, so apologize in advance if it is obvious

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 1
    Does this help? http://stackoverflow.com/questions/7375729/mvc3-3-decimal-places-on-type-double-with-leading-zero – Harry Jan 27 '16 at 13:11

1 Answers1

0

It looks like your displayformat isn't taking.

I'm guessing Model.Miles isn't a string. If not.. try this:

<div class="row">
    <div class="col-md-3">Journey distance in miles</div>
    <div class="col-md-9">@Model.Miles.ToString("#.##")</div>
</div>
Bcbury
  • 117
  • 1
  • 9