Solved

parsing dollar values - URGENT

Posted on 2004-10-14
8
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Assisted Solution

by:tusharashah
tusharashah earned 350 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 75 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 75 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 350 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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