Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there.

I need to convert from Currency to normal string.

Value $2 500.00 needs to be converted to 2500 OR
$2 499.99 to 2499.99

I tried
string test = Convert.ToString(Total.Text.Replace("$", "").Replace(".", ""));
but then i get the value 250000 or 249999 which brings my calculation into the millions.

Any help please?
Thanx
Posted

Try this,

C#
string s = "$123,456.78";
       decimal value;
       bool flag = decimal.TryParse(s,NumberStyles.Currency,CultureInfo.CurrentCulture.NumberFormat,out value);
       if (flag)
       {
           Console.WriteLine("Entered Amount is :" + value);
       }
 
Share this answer
 
v2
try by this statement..
C#
string test = Convert.ToString((Total.Text.Replace("$", "").Split("."))[0].ToString());


hope it works..
 
Share this answer
 
v2
Comments
DJAppleboy 3-Jan-12 2:42am    
Replace the double quotation marks in split with single once then it works. However, it converts $2 499.99 to 2499 and i still need the .99
you can be able to convert the currency by using multimedia if you want the code i can give you
 
Share this answer
 
Hi,

string test = Convert.ToString(Total.Text.Replace("$", "").Replace(" ", ""));


use this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900