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?
NLS Collation/Locale/Keyboard Technical Lead
Globalization Infrastructure, Fonts, and Tools
This posting is provided "AS IS" with
no warranties, and confers no rights.
"Sylvain ROSS" <foo (AT) bar (DOT) com> wrote
Change the DecimalSeparator just for one application - 07-26-2005 , 07:35 PM
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
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
|Thread Tools||Search this Thread|