473,788 Members | 2,705 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 1424
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
3636
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 Option along with a small helper function. In the code are comments describing my problem, look closely...
3
10294
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 throwing Format Exceptions all over the place. What is the "C#" way to do this??? code int wmin,...
2
3816
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
29246
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
2986
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
71457
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
5233
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 field (101 as a style parameter) and compare that to a start and stop date (both being the same) and...
1
3602
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, connected to websiteOrder.sln located in Visual Source Safe 6.0(source safe located in another...
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
10370
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...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
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
8995
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...
1
7519
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
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...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
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
3
2896
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.