473,548 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to convert this

got a string a="2.3944864845 405107E+18"

how to convert this into a valid number. which method to use..
I was using Convert.ToInt64 (a); which is going to exception.
thanks
Praveen
Jun 27 '08 #1
5 1412
try decimal.Parse() instead
Jun 27 '08 #2
Praveen skrev:
got a string a="2.3944864845 405107E+18"

how to convert this into a valid number. which method to use..
I was using Convert.ToInt64 (a); which is going to exception.

First: The string you have is not representing an integer, so you have
to go through a string to double step first.

Secondly: Converting a string to a double is language dependent, - in
German, Norwegian and French as an example the expected decimal
separator is a comma ',', instead of a period (.).

If you know that the string always is using '.' as decimal point you
should parse it by using CultureInfo.Inv ariantCulture to avoid a crash
if running on a German OS.

Int64 value = Convert.ToInt64 (Convert.ToDoub le(a,
System.Globaliz ation.CultureIn fo.InvariantCul ture));

--
Bjorn Brox
Jun 27 '08 #3
>got a string a="2.3944864845 405107E+18"
Secondly: Converting a string to a double is language dependent, - in
German, Norwegian and French as an example the expected decimal
separator is a comma ',', instead of a period (.).
I'm curious as to what will happen if you try converting this on a German
locale as it is a number in standard form and and wonder if it is an
exception or not. Could you try?
Jun 27 '08 #4
Peter Morris wrote:
>>got a string a="2.3944864845 405107E+18"
Secondly: Converting a string to a double is language dependent, - in
German, Norwegian and French as an example the expected decimal
separator is a comma ',', instead of a period (.).

I'm curious as to what will happen if you try converting this on a German
locale as it is a number in standard form and and wonder if it is an
exception or not. Could you try?
You can try it yourself just specifying a german culture as second
argument.

Arne
Jun 27 '08 #5
Peter Morris skrev:
>>got a string a="2.3944864845 405107E+18"
>Secondly: Converting a string to a double is language dependent, - in
German, Norwegian and French as an example the expected decimal
separator is a comma ',', instead of a period (.).

I'm curious as to what will happen if you try converting this on a German
locale as it is a number in standard form and and wonder if it is an
exception or not. Could you try?

Convert.ToDoubl e(a) throw a System.FormatEx ception

--
Bjorn Brox
Jun 27 '08 #6

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

Similar topics

1
1787
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance would be identical. I was 100% incorrect. The code below produces the results: CType Took: 0.2187528 seconds. Convert Took: 12.187656 seconds.
4
3609
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is of the type the object is instantiated with. In my test program I have Option<std::string> and Option<long>. Here's the code for OptionBase and...
3
10258
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function and there you have it. So I enquired and found the Convert class with it's promising ToInt32 method, great... but it doesn't work. The thing keeps...
2
3797
by: fabrice | last post by:
Hello I'm getting an error during a .vb file compilation. My command is : vbc /t:library /r:system.web.dll /r:system.dll /r:mscorlib.dll myFile.vb The error is :
7
29182
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
2
2979
by: SimonZ | last post by:
Hi, can someone explain me, when to use: (DateTime)DataBinder.Eval(Container.DataItem, "dateField") OR Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "dateField")) Sometimes (DateTime) works sometimes not, on the other hand
17
71357
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
1
5206
by: Wes Peters | last post by:
I have a situation where I want to filter records for a given day. The field that stores the date/time uses the date() function as a default value, kind of a date/time stamp for the record. The problem is when I want to filter records for a given day instead of a date range. I use the CONVERT function to return just the date part of the...
1
3580
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in some files and work on it. Let say, I want add new page to web project named websiteOrder.sln, i will open websiteOrder.sln in my local computer,...
4
5078
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
0
7707
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. ...
1
7466
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...
0
7803
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...
0
6036
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...
1
5362
isladogs
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...
0
5082
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...
0
3495
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...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
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 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.