0

I have an very frustrating issue in a simple web application I am building.

It works fine in chrome and firefox, but when using the application in Safari on an ipad (which is where it will be used in live) the data is not being formatted correctly.

For example, the data retrieved definitely uses a point (.) as a decimal seperator, and appears as such in firefox/chrome.

However, when viewing the data in safari, it appears as a comma (,) and this is messing up my database inserts.

I tried changing my region and language to United Kingdom but with no effect.

This is how I display one of the decimals in question:

@Html.LabelFor(model => model.MassOff, new { @class = "viewFieldLabel" }) <br />
@Html.DisplayFor(model => model.MassOff)

But it is even worse that this, as I also display decimals elsewhere in a WebGrid, which automatically populates itself based on class properties, so I never explicitly tell it to display the decimal. However, it still appears with a comma in the WebGrid so I ahve no idea how I'm going to change that...

Why would safari do this automatically, when I have at no point asked it to convert any formats? Do I now have to manually try and find all these values and change them using JQuery (which seems absolutely ridiculous), or is there some setting I can change on the ipad or property I need to include in my code?

Update

I managed to fix the way the decimals are displayed with a

[DisplayFormat(DataFormatString = "{0:0.###}")]

Above the properties in question. However, when submitting data, it is still being sent through with a comma (,), so it seems this only changes the way it is displayed.

Bassie
  • 9,529
  • 8
  • 68
  • 159

1 Answers1

1

It seems that you have different navigator.language on your Safari and other browsers.

Please see in this topic: Best way to determine user's locale within browser

If you can put a server-side script somewhere else on the net that simply reads the Accept-Language header and spits it back out as a JavaScript file with the header value in the string, eg.:

var acceptLanguage= 'en-gb,en;q=0.7,de;q=0.3;

then you could include a pointing at that external service in the HTML, and use JavaScript to parse the language header. I don't know of any existing library code to do this, though, since Accept-Language parsing is almost always done on the server side.

Bassie
  • 9,529
  • 8
  • 68
  • 159
VANILKA
  • 634
  • 1
  • 13
  • 32
  • thanks for your answer, but I do not know what that means. Do I now need to set up a 2nd server and run a service from there? This seems completly ridiculous. Can't I just change this `navigator.language` in safari itself? – Bassie Jun 07 '17 at 12:54