473,809 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

double.Parse and NumberFormat behavior

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(te xt1.Text) returns 2.5 as expected.
2.) If I enter the value 2,5 into a textbox the
double.Parse(te xt1.Text) returns 25...why 25 and not 2500. The , is
the group-separator.

Is it possible to ignore these behavior to ensure the 2,5 and 2.5 will
always be interpreted as 2.5 9like in the calculator) ? Or do I have
to implement this behavior by my self?

Regards
Marcel

Sep 6 '07 #1
1 2328
schaf wrote:
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(te xt1.Text) returns 2.5 as expected.
2.) If I enter the value 2,5 into a textbox the
double.Parse(te xt1.Text) returns 25...why 25 and not 2500. The , is
the group-separator.

Is it possible to ignore these behavior to ensure the 2,5 and 2.5 will
always be interpreted as 2.5 9like in the calculator) ? Or do I have
to implement this behavior by my self?
It is primitive but:

double.Parse(te xt1.Text.Replac e(",", "."), new CultureInfo("en-US", false))

Arne
Sep 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
14405
by: stf | last post by:
Hello, I use c# to start excel and to get numberformat of active cell. VBA outputs results as expected, but via c# i get result 'Standard' instead of 'General' for a call to numberformat. Why? It look's like 'numberformatlocal' is returned instead of 'numberformat'. Output of C#: Numberformat:Standard NumberformatLocal:Standard
2
1517
by: MAF | last post by:
I am seeing the following behavior for my code. If I pass in 0 the system thinks the value is a string, but if I use 0.0 I believe I get a double value. Has anyone else seen this behavior, am I doing something wrong? double tmp = Double.Parse(m_Value.ToString());
1
3167
by: Marco | last post by:
Hi all, in my system NumberDecimalSeparator is set to ',' so why doing: double toDo = double.Parse(dr.ToString())); toDo is something like 123.0 ?!?!?! Thanks in advance :-)
5
5659
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) ...
12
3201
by: Frederik Vanderhaeghe | last post by:
Hi, I have a problem converting text to a double. Why doesn't the code work: If Not (txtdocbedrag.Text = "") Then Select Case ddlBedrag.SelectedIndex Case 0 Case 1
6
38230
by: oskar | last post by:
Hello everyone. I have a problem with my program... and i kinda dunno what to do.. everything seems to work ok, but i'm getting corrupted double-linked list error =\. *** glibc detected *** corrupted double-linked list: 0x080aff40 *** Program received signal SIGABRT, Aborted. 0xaf7037b2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 (gdb) bt #0 0xaf7037b2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
2
3503
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)
8
15070
by: =?Utf-8?B?T2xpdmllciBHSUw=?= | last post by:
Hello, I try to convert a volume stored as a string value in an XML file into a Decimal object. The volume is stored with comma as decimal separator ("210,12") according to french habits. To be independent from the culture of the current user, I use decimal.Parse(volume, new System.Globalization.CultureInfo("fr-FR", true)); but this function fails with : Exception : Input string was not in a correct format.
4
2569
by: Yoavo | last post by:
Hi, I want to convert a string to double. I use the function: "System.Convert.ToDouble". The problem is that if the string contains the character "." the program aborts. What might be the problem ? Yoav.
0
9721
marktang
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...
0
9601
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,...
0
10635
Oralloy
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...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
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...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3013
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.