Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Visual-Studio
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 11-Jan-13 8:38am
_Natula879
Edited 11-Jan-13 8:46am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
decimal.Parse("(€1,25)", System.Globalization.NumberStyles.Currency);
The currency identifier and the decimal point symbol are controlled via locale information.
  Permalink  
v2
Comments
HabeshaMan at 11-Jan-13 13:56pm
   
Thank you.My problem resolved less than 5 min.
Mika Wendelius at 11-Jan-13 13:59pm
   
You're welcome :)
Maciej Los at 11-Jan-13 17:22pm
   
Nice solution, +5!
Mika Wendelius at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100