Reputation: 3041
I have an ASP.net MVC website which is displaying numbers. Can I somehow determine if the user's computer is configured to use a comma or a point as a decimal separator?
I could check the different languages in Request.UserLanguages but that would not be very accurate for determining the decimal separator.
Upvotes: 2
Views: 2319
Reputation: 18662
Since you are asking about end user's computer, the answer is no. Unfortunately web browsers don't give you such information. All you can acquire is User's preferred language, but it is a browser setting sent-out to server via HTTP Accept-Language header. That's it.
And if you think if JavaScript will give you that, the answer is no as well. It runs in the sandbox, therefore it does not have an access to Operating System.
I am not sure if Flash could access such information (possibly), but it could be blocked by end user. The same goes for an ActiveX control, plus it is not cross-platform.
So stick to the Culture detected from web browser and format number accordingly, it is just easier that way (although it won't support end user's modification of OS settings).
Upvotes: 0
Reputation: 32447
MVC has a problem handling decimal values.
There is a great post by Haack about this. It shows you how to overcome this.
Upvotes: 1
Reputation: 499312
You can see here how to get a CultureInfo
from the browser language - this will get you
a CultureInfo
object that you can use like this:
var sep = browserCulture.NumberFormat.NumberDecimalSeparator;
See CultureInfo
and NumberFormatInfo
.
Upvotes: 2