Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

parsing dollar values - URGENT

Posted on 2004-10-14
8
Medium Priority
?
338 Views
Last Modified: 2008-02-01
Hi,

I have a string = to a dollar value. eg:

string dollars = "$15.45";

how do I parse it into a decimal?

i want:

decimal decPrice == 15.45;

but i want to do it by parsing the string into a decimal.. do I use an Iformatprovider or something? please give an example, i don't know how to use iformatprovider

thanks

-Trevor
0
Comment
Question by:trevorhartman
8 Comments
 
LVL 18

Assisted Solution

by:tusharashah
tusharashah earned 1400 total points
ID: 12312070
One simple thing you can do is, befor parsing it to Decimal Replace $ with emptystring:

string dollars = "$15.45";
dollars = dollars.Replace("$",""); // new value of dollars will be 15.45 now


-tushar
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 12312094
thanks for the reply, i'll put that in place for now... but i'm curious to see how to do it with an IFormatProvider because I want to be able to use that for other things in the future.  How do I tell decimal.Parse that my string is in a currency format so it knows how to parse?

-Trevor
0
 
LVL 9

Assisted Solution

by:msdixon
msdixon earned 300 total points
ID: 12312096
and here's how to get it into a decimal value type


string dollars = "$15.45";
decimal amt = decimal.Parse(dollars.Replace("$", ""));
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 300 total points
ID: 12312104
Dim delim As String = "$"
dollars.trim(delim.ToCharArray())

Aeros
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 12312465
thx for the suggestions guys, but i'm still wondering on the IFormatProvider thing...
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 1400 total points
ID: 12312698
Hi Trevor,

Try this:
-------------------------------------------------------------------------------------------------------------------------------------
string dollars = "$15.45";
double dDollars;  
bool parse = Double.TryParse("$15.45", NumberStyles.Currency, NumberFormatInfo.CurrentInfo, out dDollars);
-------------------------------------------------------------------------------------------------------------------------------------

-tushar
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 12312805
Thanks tushar.

this did it for me:

double dollars = double.Parse("$13.40", NumberStyles.Currency);

-Trevor
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12313534
Nice to have you going!

Thanks for A

-tushar
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question