locked
Decimal value comma and dot mixed up RRS feed

  • Question

  • User306200436 posted

    Hi

    We develop a project using ASP.NET Core 2.2 MVC.

    In my model I use a property which is a decimal.

            [Display(Name = "Amount")]
            public decimal Amount { get; set; }

    In the view I use it like this:

        <div class="form-group">
            <div class="row">
                <div class="col-sm-2">
                    <label asp-for="Transaction.Amount" class="custom-label"></label>
                </div>
                <div class="col-sm-2">
                    <input asp-for="Transaction.Amount" class="form-control" />
                    <span class="text-muted">Amount including VAT. Only positive values accepted.</span>
                </div>
            </div>
            <span asp-validation-for="Transaction.Amount" class="text-danger"></span>
        </div>

    When I debug the project on my local PC the value there is displayed like this: 0.00

    When I publish it on the web server the value is: 0,00 (comma instead of dot).

    The problem is that my end users are used to put numbers in with dot (.) and if they type now 1.5 for example the value returned to the controller is 15.

    In the _Layout.cshtml file I already went over the environment settings and checked that the same jquery and javascripts are used during development and also under production envornment.

    I also played around with the regional settings of the web server itself but no difference.

    Des anybody know this kind of issue and how to solve / work around it?

    Thanks

    Saturday, July 20, 2019 6:38 PM

Answers

  • User306200436 posted

    I found the problem.

    There was some configuration done in the Startup.cs file under app.UseRequestLocalization().

    After I removed or better changed it, it works now perfect.

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 22, 2019 1:04 AM

All replies

  • User753101303 posted

    Hi,

    the regional settings of the web server

    You mean the control panel ? Instead use https://www.smarterasp.net/support/kb/a1461/how-to-set-culture-in-web_config-to-change-datetime-format.aspx to define the culture you want to use.

    Sunday, July 21, 2019 9:35 AM
  • User306200436 posted

    I've added the line in the web.config file, but still same result, even after iisreset on the server.

    This is how the web.config looks like.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    	<system.web>
    		<globalization culture="en-US" uiCulture="en-US" />
    	</system.web>
    	<location path="." inheritInChildApplications="false">
    		<system.webServer>
    			<handlers>
    				<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    			</handlers>
    			<aspNetCore processPath="dotnet" arguments=".\Portal.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    		</system.webServer>
    	</location>
    </configuration>
    <!--ProjectGuid: 5274809d-923f-418b-8dec-e8cb31d6c935-->

    If I put the following line of code in my controller and output the value of culture1.Name in both environments (dev and production) I get the same value, but not en-us but de-DE

    CultureInfo culture1 = CultureInfo.CurrentCulture;

    Monday, July 22, 2019 12:08 AM
  • User306200436 posted

    I found the problem.

    There was some configuration done in the Startup.cs file under app.UseRequestLocalization().

    After I removed or better changed it, it works now perfect.

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 22, 2019 1:04 AM