0

I would like to format a price in JavaScript.

-> 250012

it should be

-> 2.500,12

View

 <div class="form-group">
        @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
        </div>
    </div>
tom clack
  • 191
  • 3
  • 14

1 Answers1

1
> const number = 250012;
> (number/100).toLocaleString('de-DE')
< "2.500,12"

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString for browser support & more info

Mico
  • 1,978
  • 2
  • 13
  • 17