0

I try to display a decimal value.

// My Model

[DisplayFormat(DataFormatString = "{0:N2}", ApplyFormatInEditMode = true)]
public Decimal? Tax_percent { get; set; }

// My View (Try with EditorFor also)

<div class="form-group form-md-line-input form-md-floating-label no-hint">
<input type="number" name="Tax_percent" class="form-control@(!Model.Tenant.Tax_percent.HasValue ? "" : " edited")" value="@Html.DisplayFor(m => m.Tenant.Tax_percent)" step="0.01" min="0" max="100">
<label>@L("TaxPercent")</label>
</div>

The error message appear when i open my modal:

The specified value "0,00" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?" jquery.min.js:3

Thanks

5
  • 2
    You need to add some localization to your page. Take a look at this =>stackoverflow.com/questions/18218705/… Commented May 7, 2018 at 10:06
  • Show you real code (@Html.DisplayFor(m => m.Bar) is not related to the property you have shown) Commented May 7, 2018 at 10:09
  • Sorry i change to my real code @Html.DisplayFor(m => m.Tenant.Tax_percent) Commented May 7, 2018 at 10:24
  • @FranckMartin ASP.NET tries to parse text using the browser's language and the server's localization settings. That works perfectly for end users. If, like most developers, you set your user/system locale to US, you won't be able to parse non-US decimals without modifications Commented May 7, 2018 at 11:45
  • @FranckMartin you could hard-code the locale per site or page, if you are certain that all end users will use the same locale. You can do that with page directives or web.config settings. That will break if you have users from multiple countries though, especially for dates. That's why most forums have an option for end users to specify their preferred locale. Commented May 7, 2018 at 11:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.