Solved

# Currency string convertion

Posted on 2004-04-21
241 Views
If I convert a decimal representing a money sum to a string, I preferably do it using a sum.ToString("C"). The result is something like "\$123.45" or "123,45 kr", depending on your regional settings in Windows (I guess!?).

How do I convert back from the string to a decimal/float/similar? Is there a function that trims the string dependant of the regional settings?
0
Question by:IRQ
[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

LVL 9

Expert Comment

ID: 10878261
0

LVL 9

Expert Comment

ID: 10878372
If that doesn't work you may need to look at the specifics in the NumberFormatInfo.CurrentInfo object like below

string sep = System.Globalization.NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;

and the currency symbol

string symbal = System.Globalization.NumberFormatInfo.CurrentInfo.CurrencySymbol;

there are some more options in there that you can then use to convert the currency string back to the a float.

0

LVL 9

Expert Comment

ID: 10878420
Here is a very basic example

// replace the seperator either . or , or something else with a . and also replce the currency symbol with nothing
// affectively deleting it.
string sep = System.Globalization.NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;
string sym = System.Globalization.NumberFormatInfo.CurrentInfo.CurrencySymbol;
string total = txtTotal.Text;

total = total.Replace(sep,".");
total = total.Replace(sym,"");

MessageBox.Show(total);
0

Author Comment

ID: 10878625
Thanks guys, I made it myself by:
myDecimal = decimal.Parse(myString, NumberStyles.Currency, NumberFormatInfo.CurrentInfo);

Was that the same solution as yours, J?
0

LVL 9

Expert Comment

ID: 10879034
same idea, but yours is cleaner!
0

Accepted Solution

ee_ai_construct earned 0 total points
ID: 11756995
PAQed, with points refunded (500)
ee_ai_construct - CS Mod
0

## Featured Post

Question has a verified solution.

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

### Suggested Solutions

C# XML Get Values 4 54
Send parameters via datatable ajax call 4 48
asp.net repeater server posting 5 39
C#line chart with data on Y and time on X-axis 3 33
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed toâ€¦
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. Thatâ€™s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With companâ€¦
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
###### Suggested Courses
Course of the Month2 days, 22 hours left to enroll