Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

parsing dollar values - URGENT

Posted on 2004-10-14
8
Medium Priority
?
337 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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