Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a function which converts:-
1) ($1.25) to -1.25
2) $1.25 to 1.25
To do further basic mathematical calculation. like Addition.

I have tried using System.Text.RegularExpressions.Regex() and System.String .Format(),but no luck.Please help.
Posted
Updated 11-Jan-13 7:46am
v3

1 solution

Have you already tried using Decimal.Parse Method (String, NumberStyles)[^]

This method lets you to define different flags how to interpret the input string.

For example with my locale the following converts corrrectly:
C#
decimal.Parse("(€1,25)", System.Globalization.NumberStyles.Currency);

The currency identifier and the decimal point symbol are controlled via locale information.
 
Share this answer
 
v2
Comments
[no name] 11-Jan-13 13:55pm    
perfect :) increased my GK :)
_Natula 11-Jan-13 13:56pm    
Thank you.My problem resolved less than 5 min.
Wendelius 11-Jan-13 13:59pm    
You're welcome :)
Maciej Los 11-Jan-13 17:22pm    
Nice solution, +5!
Wendelius 12-Jan-13 2:55am    
Thanks :)

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