D
D
DenisVladimirovich2019-08-01 11:13:16
ASP.NET
DenisVladimirovich, 2019-08-01 11:13:16

ASP.NET Core and floating point in EFCore. How to implement?

Good day gentlemen. Tell. I'm suffering for a while. Is it not possible to enter values ​​with a dot into the database through web forms? It seems like a float is a floating point value, but I can only enter a semicolon into the base. SQL Server base. The fields in the model are float. Tried double, same thing. in basis in properties of the table I see that float is specified. The model also seems to be in order. But every time when I try to score through the value form with a dot, I swear that the data is not valid for the field.

var cultureInfo = new CultureInfo("ru-RU");
            cultureInfo.NumberFormat.NumberDecimalSeparator = ".";
            System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;

Such a line was specially added for forced accounting, so to speak. But nothing helps.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Planet_93, 2019-08-01
@Planet_93

Alternatively, replace the dot with a comma.
Here you get a model for writing to the controller.
Fields, where we convert numbers into a string and do a replay.

public ActionResult Edit(string number)
    {
      number = number.ToString().Replace(".",",");
      return View();
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question