Click here to Skip to main content
12,250,675 members (51,662 online)
Rate this:
 
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 7:38am
_Natula890
Edited 11-Jan-13 7: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 11-Jan-13 13:56pm
   
Thank you.My problem resolved less than 5 min.
Mika Wendelius 11-Jan-13 13:59pm
   
You're welcome :)
Maciej Los 11-Jan-13 17:22pm
   
Nice solution, +5!
Mika 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2016
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