473,586 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Thanks in advance.
Nov 16 '05 #1
3 3091
System.Convert. ToDecimal(strin g)

"Will" <an*******@disc ussions.microso ft.com> wrote in message
news:9A******** *************** ***********@mic rosoft.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";
NumberFormatInf o nfi = new NumberFormatInf o();
nfi.CurrencyDec imalSeparator = ".";
decimal dec = decimal.Parse(s , nfi);
Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
"Will" <an*******@disc ussions.microso ft.com> wrote in message
news:9A******** *************** ***********@mic rosoft.com...
Thanks in advance.

Nov 16 '05 #3
Use System.Convert

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

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

Similar topics

5
1895
by: Duck Dodgers | last post by:
Here is my situation class base { }; class child1 { int data; }; class child2 {
6
2192
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 language="JavaScript" src="http://www.topcounters.com/pphlogger.js?id=johnsmith"> </script>
5
8972
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 format (decimal, octal with leading zero, hex with leading "0x") and have C# get the conversion right. I hope I'm missing something, but it...
1
3887
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 limitations of numerical precision of the double type, I'm presuming that the value will be stored in a decimal for the time being. Supposing the...
10
5863
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 if I'm running it in a console app or in a web app, what's up with that?). I'm trying to get a counter (int) value out of the Application object. ...
3
6504
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 variable(for example 12,3 or 12.3). After saving record, value(12,3 or 12.3) is saved as 123, not 12,3 or 12.3... I'm using ADO.NET for processes in...
4
3736
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 strings with a leading minus sign toi ndicate a negative number. One last improvement might be to print a warning if the string represents a...
13
1768
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" - string "123" : value = the integer 123 - string "-1.23" (or "-1,23" if the locale for decimals is ,) : value = the float -1.23 - string "2008/03/06"...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.