Decimal and Thousands separator

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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Just pass the underlying number instead of a string.  Any formatting should only be for display purposes.
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:
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.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Remote Access

From novice to tech pro — start learning today.