Hi,
I use the double.Parse functionality to convert a number
in a text file into a double. However, while this works
fine on one computer it doesn't on another. I've found
out that it is dependent on the comma seperator settings
on the computer. Is there a way to override this - I
would like double.Parse to always use a . as comma
seperator no matter what the system settings are.
Thanks
Jesper 4 12226
Well, what you WANT it to do is irrelevant, Parse is SUPPOSED to obey system
settings.
Use another convertion means (like te Convert class), or set the thread's
culsture settings explicitly.
Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
"Jesper Denmark" <an*******@disc ussions.microso ft.com> wrote in message
news:01******** *************** *****@phx.gbl.. . Hi,
I use the double.Parse functionality to convert a number in a text file into a double. However, while this works fine on one computer it doesn't on another. I've found out that it is dependent on the comma seperator settings on the computer. Is there a way to override this - I would like double.Parse to always use a . as comma seperator no matter what the system settings are.
Thanks Jesper
Well, Thomas could be right, but I thought you could go:
double.Parse("< your string to parse here>", CultureInfo.Inv ariantCulture)
which would use the settings that you used when you wrote the code and not
the user's cultural settings. I could be wrong, but if that doesn't work
you might look into the IFormatProvider interface.
Hope this helps,
Jacob
"Jesper Denmark" <an*******@disc ussions.microso ft.com> wrote in message
news:01******** *************** *****@phx.gbl.. . Hi,
I use the double.Parse functionality to convert a number in a text file into a double. However, while this works fine on one computer it doesn't on another. I've found out that it is dependent on the comma seperator settings on the computer. Is there a way to override this - I would like double.Parse to always use a . as comma seperator no matter what the system settings are.
Thanks Jesper
Jesper Denmark <an*******@disc ussions.microso ft.com> wrote: I use the double.Parse functionality to convert a number in a text file into a double. However, while this works fine on one computer it doesn't on another. I've found out that it is dependent on the comma seperator settings on the computer.
By "comma separator settings" do you actually mean the decimal
separator?
Is there a way to override this - I would like double.Parse to always use a . as comma seperator no matter what the system settings are.
Use the form of Double.Parse which takes an IFormatProvider , and give
it CultureInfo.Inv ariantCulture, eg:
double d = Double.Parse (myString, CultureInfo.Inv ariantCulture);
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thomas Tomiczek [MVP] <t.********@tho na-consulting.com> wrote: Well, what you WANT it to do is irrelevant, Parse is SUPPOSED to obey system settings.
Well, the version of Parse which doesn't take an IFormatProvider is...
Use another convertion means (like te Convert class), or set the thread's culsture settings explicitly.
Changing the thread's culture setting sounds like a really bad idea to
me - just passing in the appropriate culture to the overload of Parse
which takes an IFormatProvider is far cleaner, IMO.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kevin |
last post by:
Why do I get different values for the same hex string when parsing to an
integer versus a double? See the follwoing code snippet:
using System;
using System.Collections;
using System.Threading;
public class MyClass
{
public static void Main()
|
by: Adam Klobukowski |
last post by:
Hello
I need to convert some strings int doubles.
Unfortunetly strings do not follow my country culture standarts (we use
, to separate decimal from fraction, but strings use . there etc.).
Also, I have to convert those doubles back to strings, and I need to use
other standars then my culture (ie. use . instead of ,).
|
by: slylos |
last post by:
I've got a section of code in my app that keeps track of how much time an
employee has accrued, which equals out to 1.33 days of PTO per month. I'm
trying to store the time accrued so far in an XML file. I have no problems
writing to and reading from the XML file and all my values are correct. The
problem I'm having is my calculation never amounts to 1.33, it goes from
1.32999999999997
to
1.3743333333333.
on the next run.
|
by: Markus Kling |
last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception:
Value was either too large or too small for a Double.
at System.Number.ParseDouble(String value, NumberStyles options,
NumberFormat
Info numfmt)
at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
at System.Double.Parse(String s)
...
|
by: Daniel Walzenbach |
last post by:
Hi,
I wonder if somebody could explain me the difference between Double.Parse and Convert.ToDouble. If I'm not mistaken they are implemented differently (I though for a moment they might be the same like cint(anInt) and cType(anInt, System.Int32) but I checked with ildasm) - if I didn't made a mistake.
So when to use which syntax? Is there any performance penalty when using the one over the other or does anybody knows any differences?
'...
| |
by: Samuel R. Neff |
last post by:
I'm using a quasi open-source project and am running into an exception
in double.Parse which is effectively this:
double.Parse(double.MinValue.ToString())
System.OverflowException: Value was either too large or too small for
a Double.
at System.Number.ParseDouble(String s, NumberStyles style,
NumberFormatInfo info)
|
by: schaf |
last post by:
Hi NG!
I have a little question about the localization of a double.
If I use the CultureInfo "en-US" I have the following behavior:
1.) If I enter the value 2.5 into a textbox the
double.Parse(text1.Text) returns 2.5 as expected.
2.) If I enter the value 2,5 into a textbox the
double.Parse(text1.Text) returns 25...why 25 and not 2500. The , is
the group-separator.
|
by: schlied |
last post by:
Hello,
i have the following problem in our project:
If I try to parse a string value with the following line
double x = double.Parse("39.95238", CultureInfo.InvariantCulture);
x contains 39.9523799999.... instead of the correct one.
What could be the reason for that?
Thanks in advance
|
by: Mika M |
last post by:
Hi,
Just for fun I'm trying to parse my GPS position string using C# 2005.
When my code is trying to parse latitude string to double value like...
double.Parse(items); // items = "6215.1058"
....I'll just get an error. What's wrong with that?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |