Click here to Skip to main content
Click here to Skip to main content

Convert String To Decimal

, 5 Jun 2006
Rate this:
Please Sign up or sign in to vote.
How convert a string to a decimal using .NET
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->


I tried to convert a currency string ("$ 1.200,00") to decimal using c# and VS2005, I can't did it using Decimal.Parse("$ 1.200,00"). 
Allways the error message was "Input String was not in a correct format".  But I saw
I was using the correct format.


Then I retrieved a old code using NumberStyles. I used the same code but the error still the same.

I did test the line code and when I removed the space from the currency string. Voila, it works.

This is the function.

private decimal ToDecimal(string Value)
 if (Value.Length == 0)
                return 0;
                return Decimal.Parse(Value.Replace(" ", ""), NumberStyles.AllowThousands 
   | NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol);


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Colombia Colombia
No Biography provided

Comments and Discussions

GeneralThank You ! Pinmemberpolczym8-May-10 9:42 
GeneralNice PinmemberRavi J Patel4-May-10 20:15 
GeneralConvert string to decimal , rithy(cambodia) Pinmemberthyrith30-Mar-10 22:54 
GeneralSolution Pinmemberrosilvioro21-Jul-09 3:48 
JokeExcelent Article PinmemberJuan Carlos Chávez Trinidad24-Jun-09 17:34 
GeneralMy vote of 1 Pinmemberlousyprogrammer4-Jun-09 19:05 
GeneralMy vote of 1 Pinmembermuz@dogru.ch19-Dec-08 1:49 
General',' vs '.' PinmemberEuGenius_Krivbass24-Apr-08 6:53 
GeneralRe: ',' vs '.' Pinmemberbeimklabautermann3-Jun-10 6:39 
GeneralThank You PinmemberNachiappanR10-Jul-07 22:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 6 Jun 2006
Article Copyright 2006 by Edusie
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid