Decimal with ASP.NET Core 2.2

Asked

Viewed 155 times

0

I have an ASP.NET Core 2.2 project with the following configuration in the Startup class

        var cultureInfo = new CultureInfo("pt-BR");

        CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
        CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

        var supportedCultures = new[] { cultureInfo };
        app.UseRequestLocalization(new RequestLocalizationOptions
        {
            DefaultRequestCulture = new RequestCulture(culture: "pt-BR", uiCulture: "pt-BR"),
            SupportedCultures = supportedCultures,
            SupportedUICultures = supportedCultures
        });

The model has the following tags

    [DisplayName("Valor")]
    [DataType(DataType.Currency)]
    [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:C2}")]
    public decimal Valor { get; set; }

When I post the system does not recognize the comma as decimal separator.

What I need to add to solve the problem?

  • Note, decimal is not the suitable type to work with monetary values, I would use double... How this data is coming from the interface?

  • @Leandroangelo, the ideal for monetary valuation is the same decimal. Why double, could explain?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.