Click here to Skip to main content
11,928,786 members (59,059 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 8:38am
Edited 11-Jan-13 8:46am

1 solution

Rate this: bad
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.
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
Web04 | 2.8.151126.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2015
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