0

I'm running the ASP .NET application through Visual Studio. The latitude and longitude data are retrieved from an SQL Server database. The application works with no issue when run through Visual Studio localhost, but when i deploy it to IIS the data is displayed without the decimal point.

The data type in the database is a float.

TestTable modal class to retrieve the data from the database.

public class TestTable
{
    public int ID { get; set; }
    public string Product_Description { get; set; }
    public int PolicyNo { get; set; }
    public string Insured { get; set; }
    public string TAB_Ratio { get; set; }
    public string Broker_Name { get; set; }
    public DateTime Policy_Inception_Date { get; set; }
    public string Match { get; set; }
    public string Detail_Address { get; set; }
    public int Building_SI { get; set; }
    public decimal Total_API_Outside { get; set; }
    public decimal Rate { get; set; }
    public decimal Total_Loss_Ratio { get; set; }
    public decimal ThrdParty_Loss_ratio { get; set; }
    public decimal ThrdParty_Attritional_Ratio { get; set; }
    public double Lat { get; set; }
    public double Long { get; set; }
}

Foreach to retrieve the data from the TestTable

@{ var mapCounter = 0;}
@foreach (var item in Model.TestTable) {
   if(mapCounter < 200)
   {
      mapCounter++;
      <text>
         console.log(@item.Lat);
      </text>
      @:addMarker(@item.Lat, @item.Long, '@item.ID', '@item.Product_Description', '@item.Insured', '@item.TAB_Ratio', '@item.Broker_Name', '@item.PolicyNo', '@item.Match', '@item.Detail_Address', '@item.Building_SI', '@item.Total_API_Outside', '@item.Rate', '@item.Total_Loss_Ratio', '@item.ThrdParty_Loss_ratio', '@item.ThrdParty_Attritional_Ratio');
     }
 }

function to create markers based on the data from the database

 function addMarker(latitude, longitude, title, description, insured, tab_ratio, broker_name, policy_inception, match, detail_address, building_si, total_api_outside, rate, total_loss_ratio, thrdparty_loss_ratio, thrdparty_attritional_ratio)
 {
     var latLng = new google.maps.LatLng(latitude, longitude);

     var marker = new google.maps.Marker({
         position: latLng,
         title: title,
         map: map,
         icon: icon,
         draggable: false
     });

     allMarkers.push(marker);
 }

See the console for output.

Top image from Visual Studio. Bottom image from IIS server.

Thank you in advance.

Visual Studio Localhost.

IIS Server

IIS Server console.log output

Winde
  • 7
  • 2
  • Could you please include some more information? For example, what data type are you using to store the latitude & longitude in the database? Also, could you show us the code that retrieves the data from the database, as well as any code that manipulates the data? – Kei Nov 08 '19 at 10:40
  • Thanks for the update. This is quite odd. Could you "View Source" on the IIS Server, and show me the `console.log` part? I'd like to see how the `console.log(@item.Lat);` is actually getting rendered – Kei Nov 08 '19 at 12:56
  • Yeah it is very odd. I'm rather new to IIS so would you please explain the "View Source" to me? – Jeandre Jonker Nov 08 '19 at 13:11
  • Ah sorry, I meant try opening the site in your browser. Once open, right click -> View Source (or ctrl+U on some browsers). By `on the IIS Server` I meant viewing the source for the site hosted on IIS as opposed to localhost. – Kei Nov 08 '19 at 14:31
  • @Kei, I added a link to show the output from IIS Server. On localhost the lat and long are displayed with a point. On the IIS Server it seems to be displayed with a comma. Any thoughts? Thank you for your assistance. – Jeandre Jonker Nov 11 '19 at 05:40
  • @Jeandre Jonker -- try comparing your region settings from your localhost machine to the machine you deployed iis on, i ran into this issue a lot and usually it was my region settings/formats on the server that was different from that of my localhost. – A. Kriel Nov 11 '19 at 05:40
  • Ah... I think I get it. console.log is interpreting your coordinate as two separate arguments. For instance, `console.log(-33,01424)` is interpreted as passing two parameters (`-33` and `1424`). This also explains why the leading 0 after the "," is being stripped out in the output. As to why a `,` is being output instead of `.`, as @A.vdWalt stated, this is probably due to the production server having a different region setting. There are many countries that use a "comma" as a decimal point, and I suspect your IIS Server is set to follow one of these countries. – Kei Nov 11 '19 at 06:06
  • To get around it, one quick solution might be to specify the format specifically. For example, `@item.Lat.ToString("#.####")` (the # repeated for as many decimal places as you need). Haven't tested it but overriding the current thread culture (and/or UICulture?) may work. Finally, you can [use the NumberFormatInfo class](https://stackoverflow.com/a/18377793/11981207) to explicitly set the number decimal separator to a `.` – Kei Nov 11 '19 at 06:13
  • Thank you for the info guys. I'm busy looking into the regional settings for the IIS Server and that seems to be the problem. I will post a solution when i get to it. Many thanks! – Jeandre Jonker Nov 11 '19 at 06:14
  • If you want to change the region settings for the whole server, I believe you can find it tucked away here: `Control Panel` > `Region` > `Additional settings...` > `Decimal symbol` – Kei Nov 11 '19 at 06:18
  • Thank you for your help guys. I appreciate the feedback. I got a working solution. – Jeandre Jonker Nov 11 '19 at 08:25

1 Answers1

0

For the interest to anyone who has the same problem. The problem is with regional settings in the ASP .NET Application. On default it is set to a comma. A work around that worked for me was to set the value to a string format with the "." as a separator.

using System.Globalization;

console.log(@string.Format(CultureInfo.InvariantCulture,"{0:#.#############################}",item.Lat));
console.log(@string.Format(CultureInfo.InvariantCulture,"{0:#.#############################}",item.Long));

This sets the regional number format to the application no matter on which regional settings the machine is set to.