473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Convert a currency string to a double

Hi All,

I'm am looking to convert a currency string (e.g. "$1,234.56" to a
double value).

It appears this will work:

double val = Convert.ToDouble(Double.Parse*("$123,456.78901",
System.Globalization.NumberSty*les.Currency));

My question is, why doesn't this appear to work (which was my inital
attempt at solving this problem):

double iPurchasePrice = Convert.ToDouble(PurchasePrice,
NumberFormatInfo.CurrentInfo);

It results in the exception:

System.FormatException: Input string was not in a correct format.

It appears to be choking on the "$" symbol. When I remove that it
works. I tried creating my own NumberFormatInfo supplying all of the
Currency related properties including CurrencySymbol, but it still
appears to have problems with the "$" sign.

Anyone know why this might be? Again, the Parse method works fine, I'm
just more curious if anyone had any further insight.

Thanks,
John

Nov 17 '05 #1
0 8336

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

Similar topics

2
by: Juan | last post by:
Best way to convert back a currency string into a number(int or long)? If I have, for example, $ 15.000,00 what is the best way to make it again an int or long? pls help!, Juan.
3
by: Mark | last post by:
How do you parse a currency string to a decimal? I'd like to avoid having to parse the number out, removing the $ manually. That sounds like a hack. There are times that this string will be...
2
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
2
by: zlf | last post by:
Hi, Run this code will cause format exception. I think the problem is induced by using System.Globalization.NumberStyles.Currency since I used customed currency symbol("My Dollar:"). Please tell...
2
by: KB | last post by:
Hi guys, In my DataGrid I have a column that displays decimal values as currency ( I set the Data Formatting expression of that column to {0:C}). So the actual string displayed in the grid looks...
1
by: ACaunter | last post by:
Hi all, I was wondering if there was a way to convert a double value to currency. sometimes the double number is: 7 or 7.7 or 7.77 or 7.776543 I needed to always get a decimal and 2 digits after...
3
by: Josh | last post by:
I am writing a program where the user inputs currency in US dollars. I want the program to only accept valid currency input, converting the string into the proper type of variable (double?), and...
1
by: joe | last post by:
how to convert string to money before to insert to sql serve(sql db)
5
by: Eric | last post by:
Java has this. Anyone know of a .Net equivalent? Thanks, Eric
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.