473,394 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do you convert a string value "123.45" to a decimal data type

Thanks in advance.
Nov 16 '05 #1
3 3080
System.Convert.ToDecimal(string)

"Will" <an*******@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
Thanks in advance.

Nov 16 '05 #2
Use either System.Convert.ToDecimal or decimal.Parse method. Make sure that
the decimal separator for the current culture is the same as the one you're
trying to parse - otherwise you might get a FormatException (parse method)
or an unpredicted result in some cases.

Here is the example with the Parse method :

string s = "123.45";
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.CurrencyDecimalSeparator = ".";
decimal dec = decimal.Parse(s, nfi);
Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
"Will" <an*******@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
Thanks in advance.

Nov 16 '05 #3
Use System.Convert

decimal d = Convert.ToDecimal("123.45");
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Duck Dodgers | last post by:
Here is my situation class base { }; class child1 { int data; }; class child2 {
6
by: |-|erc | last post by:
Hi, can a .js file read a parameter into it from the HTML file? this is the code to use in peoples HTML files, each member has their own id. <!-- TopCounters Code START --> <script...
5
by: Andrew Lighten | last post by:
Hi all; I'm really struggling to get C# to do the right thing when parsing non-decimal strings as numbers. What I really want to be able to do is take a string containing an integer in any valid...
1
by: Julie | last post by:
I have the need to preserve the precision of a user-entered number, but that needs to be stored in a (non-string) floating point variable (such as double or decimal). Due to the internal...
10
by: Flip | last post by:
I know the int.Parse("123") will result in an int of 123, but what happens with a null? I believe it give a null exception (seems like I get either NullArgumentException or ArgumentNullException...
3
by: Brenny | last post by:
Hello I'm developing a project by using access database and there is a table(Table1) and it has a field(ml_mik) this is the decimal field. I'm taking a value from windows form as a decimal...
4
by: thyagi | last post by:
a function which takes a string (pointer to char) as a parameter and returns the integer equivalent.str2int("1658") would return the value 1658 To improve your program change the function to accept...
13
by: Pierre Quentel | last post by:
Hi, I would like to know if there is a module that converts a string to a value of the "most probable type" ; for instance : - if the string is "abcd" the value is the same string "abcd" -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.