HighTechTalks DotNet Forums  

Change the DecimalSeparator just for one application

Dotnet Internationalization microsoft.public.dotnet.internationalization


Discuss Change the DecimalSeparator just for one application in the Dotnet Internationalization forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Michael \(michka\) Kaplan [MS]
 
Posts: n/a

Default Re: Change the DecimalSeparator just for one application - 07-26-2005 , 11:02 AM






Try creating a new CultureInfo and then setting the CurrentThread's
CurrentCulture to *be* that culture, after you have changed the property you
want to change.

Though honestly finding a way to work within the user's pereferences is
better -- why would the user be creating files with what they consider to be
the wrong formats?


--
MichKa [Microsoft]
NLS Collation/Locale/Keyboard Technical Lead
Globalization Infrastructure, Fonts, and Tools
Blog: http://blogs.msdn.com/michkap

This posting is provided "AS IS" with
no warranties, and confers no rights.



"Sylvain ROSS" <foo (AT) bar (DOT) com> wrote

Quote:
Hi there,
We have coded a pretty big application that's dealing with plain text
files containing float numbers with the format "33.21" for instance.

So what we are doing when importing those files into our app is
myFloatNumber = Csng(myNumberStr)

Everything worked find until we tried our app on a French and a Russian
operating system. Since the Decimal Separator for France and Russia is
",", the CSng cast crashes becose "33.21" means nothing ("33,21" wowuld
have been correct).

A radical solution would be to set the regional settings of the computer
to Decimal Separator = "," but we can't ask our russian customers to do so
just for our software.

Another solution would have been to change all the lines where we are
doing a cast from String to Single and Double (you may have heard about
CultureIndependant stuffs), but it's a huge pain in the arse to change our
code (and it seems that doing some CultureIndependant cast may result in
weird stuff.).


My idea were finally to set the DecimalSeparator to ".", but just for our
application, not for the entire system. I was pretty happy to see that the
property

system.Globalization.CultureInfo.CurrentCulture.Nu mberFormat.NumberDecimalSeparator
= "."

would be enough, but unfortunately I got an exception telling me that the
propery is readonly :

An unhandled exception of type 'System.InvalidOperationException' occurred
in mscorlib.dll

Additional information: Instance is read-only.


Then I'm looking for a way to set the DecimalSeparator at the beginning of
my app, that's all !


Thx in advance


Sylvain



Reply With Quote
  #2  
Old   
Sylvain ROSS
 
Posts: n/a

Default Change the DecimalSeparator just for one application - 07-26-2005 , 07:35 PM






Hi there,
We have coded a pretty big application that's dealing with plain text
files containing float numbers with the format "33.21" for instance.

So what we are doing when importing those files into our app is
myFloatNumber = Csng(myNumberStr)

Everything worked find until we tried our app on a French and a Russian
operating system. Since the Decimal Separator for France and Russia is
",", the CSng cast crashes becose "33.21" means nothing ("33,21" wowuld
have been correct).

A radical solution would be to set the regional settings of the computer
to Decimal Separator = "," but we can't ask our russian customers to do
so just for our software.

Another solution would have been to change all the lines where we are
doing a cast from String to Single and Double (you may have heard about
CultureIndependant stuffs), but it's a huge pain in the arse to change
our code (and it seems that doing some CultureIndependant cast may
result in weird stuff.).


My idea were finally to set the DecimalSeparator to ".", but just for
our application, not for the entire system. I was pretty happy to see
that the property

system.Globalization.CultureInfo.CurrentCulture.Nu mberFormat.NumberDecimalSeparator
= "."

would be enough, but unfortunately I got an exception telling me that
the propery is readonly :

An unhandled exception of type 'System.InvalidOperationException'
occurred in mscorlib.dll

Additional information: Instance is read-only.


Then I'm looking for a way to set the DecimalSeparator at the beginning
of my app, that's all !


Thx in advance


Sylvain

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.