• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 73
  • Last Modified:

Decimal and Thousands separator

Hi,
I have a problem with an application, I think it has to do with the regional settings.
I have a server with DB Sql Server where the regional settings for numeric formatting are:

Decimal separator (,)
Thousands separator (.)

Some workstations that access via TerminalServices to the server are formatted with the regional settings above, but others have other regional settings such as:

Decimal separator (.)
Thousands separator (,)

Apparently if the workstation is with the same settings of number of the server the calculations are correct, however if they have with the definitions of the 2º exam, in practice the calculations are incorrect. For example. 23000 (twenty three thousand) appears like 23,000 (twenty three)

There will be a way to solve this problem.

best regards
0
rflorencio
Asked:
rflorencio
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
Just pass the underlying number instead of a string.  Any formatting should only be for display purposes.
2
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Your code could always force the culture to be that of the server:

System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("de-DE");

Open in new window


For a list of available culture names scroll down towards the bottom of this list:
https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.110).aspx
0
 
sarabandeCommented:
if you want to handle the separators yourself, you could get the locale settings by WINAPI function GetLocaleInfo

    char szDefDec[4] = {0};
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SMONDECIMALSEP, szDefDec, sizeof(szDefDec));
    char szDefGrp[4] = {0};
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SMONTHOUSANDSEP, szDefGrp, sizeof(szDefGrp));

Open in new window


the above is c code which also could be used (with little changes) in vb or c#.

for example you could remove the thousands group separator - if any - from string and replace decimal separator character by a period character. then you should be able to using a toDouble conversion without issues.

note, if you don't want to bother with locale seperators at all and have some information which range the numbers are in and how many digits the decimal fraction is, you could do a reverse loop on the string which might match the following pattern "##'###,##". then you would remove the ' and replace the comma by a period in order to get a valid string number that can be converted to double. you even could use a regular expression for this.

Sara
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Best option is to have all workstations with the same configuration. This will avoid many headaches.
Today is this issue with the numbers, tomorrow will be about the dates and who knows what else will follow.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now