Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to remove specified format in string? 2

Status
Not open for further replies.

budjo

Programmer
Mar 4, 2004
19
PH
hello .. i have a simple problem but couldn't get around it ..

i loaded a record on a database ... with a specific field "amount"

i converted "amount" to double then used .ToString("c") :

(System.Convert.ToDouble(rows[0]["amount"])).ToString("c")

which gave me exactly what i what the amount with "$" infront of it
..

the problem now is converting the amount (with the $ on the beginning back to double type)

i tried System.Convert.ToDouble(amount) but it keeps saying

" Input string was not in a correct format" ..

so the question is how do you remove the formating you added on a string ???

tnx
 
i use:

Code:
System.Convert.ToDouble(strAmount.Replace("$", string.null).Replace(",", string.null))

but i could be wrong.

mr s. <;)

 
As long as you're only storing US currency, removing the dollar-sign and the commas should work.

If you have to store & display multiple currencies, you should store two variables for each currency value -- the numeric representation, and the one that gets formatted for display to the user.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
You can also use the Parse method of Double with NumberStyles

string s = "$1,123.45";
Globalization.NumberStyles ns = (Globalization.NumberStyles.Currency);
double d = double.Parse(s, ns);

- free online Compare/Diff of snippets
 
yes johnyingling solution worked .. thanks man ..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top