Decimal places with DOT

Decimal places with DOT

fpinhofpinho Posts: 4Questions: 0Answers: 0
edited July 2023 in Editor

Hello!
I'm using C# and ASP.NET CORE 6.0.

Code:

                      .Field(new Field("Analytic.AnalyticPercentage")
                        .Xss(false)
                        .GetFormatter((d, t) => Utils.SetDecimalPlaces((decimal)d, false, SymbolType.Empty))
                        .Validator(Validation.Numeric())
                        .SetFormatter((val, data) =>
                        {
                            decimal value = 0;
                            string valor = val.ToString().Replace(",", ".");
                            if (decimal.TryParse(valor, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out decimal parsedObsPercentage))
                            {
                                value = parsedObsPercentage;
                            }
                            return value;
                        })
                    )

Problem:
When on i insert on input of row 40.45 (with DOT) on SetFormatter i receive 4045 loses decimal separator.
If i insert 40,45 (with comma works fine).
How can i solve this problem?

Obs: I'm doing everything on Server-Side.

Thanks.
Regards.

Replies

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Sounds like it might be locale related.

    What happens it you comment out the if statement - lines 9-12 above? Just let the database receive the string value with the comma replaced.

    Allan

Sign In or Register to comment.