473,786 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unformatting formatted strings?

I am displaying money values in a textbox like this:
txtCountryPack. Text = String.Format(" {0:c}", dr[0]["Pack"]);

I then need to updated my Database:
decimal packPrice = Convert.ToDecim al(txtCountryPa ck.Text.Trim()) ;

The problem is that the value is in a formatted format i.e. $300.00
How do I remove the formatting with have to do a SubString?

Cheers.

S
Nov 15 '05 #1
2 12550
SamIAm,
Consider using Decimal.Parse directly instead, Convert.ToDecim al indirectly
calls Decimal.Parse.

There is an overloaded version that accepts the Globalization.N umberStyles
enum.

There is a NumberStyles.Cu rrency value, which will parse out the numeric
dollar amount.

decimal packPrice = Decimal.Parse(t xtCountryPack.T ext.Trim(),
NumberStyles.Cu rrency);

The other option is to use the overloaded Convert.ToDecim al that accepts a
format provider, if there is a format provider that is a Currency amount.

Hope this helps
Jay

"SamIAm" <sa****@rubbach icken.com> wrote in message
news:OU******** *****@TK2MSFTNG P12.phx.gbl...
I am displaying money values in a textbox like this:
txtCountryPack. Text = String.Format(" {0:c}", dr[0]["Pack"]);

I then need to updated my Database:
decimal packPrice = Convert.ToDecim al(txtCountryPa ck.Text.Trim()) ;

The problem is that the value is in a formatted format i.e. $300.00
How do I remove the formatting with have to do a SubString?

Cheers.

S

Nov 15 '05 #2
Thanks - works like a charm

S
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
SamIAm,
Consider using Decimal.Parse directly instead, Convert.ToDecim al indirectly calls Decimal.Parse.

There is an overloaded version that accepts the Globalization.N umberStyles
enum.

There is a NumberStyles.Cu rrency value, which will parse out the numeric
dollar amount.

decimal packPrice = Decimal.Parse(t xtCountryPack.T ext.Trim(),
NumberStyles.Cu rrency);

The other option is to use the overloaded Convert.ToDecim al that accepts a
format provider, if there is a format provider that is a Currency amount.

Hope this helps
Jay

"SamIAm" <sa****@rubbach icken.com> wrote in message
news:OU******** *****@TK2MSFTNG P12.phx.gbl...
I am displaying money values in a textbox like this:
txtCountryPack. Text = String.Format(" {0:c}", dr[0]["Pack"]);

I then need to updated my Database:
decimal packPrice = Convert.ToDecim al(txtCountryPa ck.Text.Trim()) ;

The problem is that the value is in a formatted format i.e. $300.00
How do I remove the formatting with have to do a SubString?

Cheers.

S


Nov 15 '05 #3

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

Similar topics

4
3156
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the drama) I've been trying to think of good ways to get Perl code to run inline in a PHP script. Here are a few of my ideas. If anyone has any further ideas, resources, or knows of someone else who's solved this already, please do tell... 1.) The...
6
22216
by: Tuang | last post by:
I've been looking all over in the docs, but I can't figure out how you're *supposed* to parse formatted strings into numbers (and other data types, for that matter) in Python. In C#, you can say int.Parse(myString) and it will turn a string like "-12,345" into a proper int. It works for all sorts of data types with all sorts of formats, and you can
4
4303
by: Joerg Lehmann | last post by:
I am using Python 2.2.3 (Fedora Core 1). The problem is, that strings containing umlauts do not work as I would expect. Here is my example: >>> a = 'äöü' >>> b = '123' >>> print "%-5s %-5s\n%-5s %-5s" % (a,a,b,b) äöü äöü 123 123 I would expect, that the displayed width of a or b is the same: 5 characters.
7
2006
by: Thomas Philips | last post by:
I want to print "1 spam 4 you" using a formatted string that gets its inputs from the dictionary d={'n1':1, 's1':'spam', 'n2':4}. To do so, I write >>> x="%('n1')d %('s1')s %('n2')d you" >>> x % d Traceback (most recent call last): File "<pyshell#22>", line 1, in -toplevel- x % d
12
5622
by: BGP | last post by:
I am working on a WIN32 API app using devc++4992 that will accept Dow Jones/NASDAQ/etc. stock prices as input, parse them, and do things with it. The user can just cut and paste back prices into a window and hit a button to process it. The information thus enters the program as a char array. Prices can be between $1 and $100, including cents. So we can have prices such as 3.01, 1.56, 11.57, etc. The char array is an alphanumeric...
1
2011
by: crater | last post by:
Have any of you good folks out there got an elegant solution for unformatting currency values for writing back to SQLServer: e.g.: $10,100,200.59 to 10100200.59 but for any locale and any currency.
3
2030
by: Wynn Rostek | last post by:
In C# is there any way to do formatted printing like there is in C? In C, I would do sprintf(string, "%4.2f",floatvalue) to print a float value with two decimal places. I have looked around a bit, but have not run across anything like this in C#, maybe I am just missing something. Many thanks, Wynn
3
2500
by: Bjarne Nielsen | last post by:
Hi all In my C# program I need to read a file, which is exported from a DOS program. So words such as "Afløser" (with special danish characters) is read like "Afl�ser". How do I decode/encode DOS formatted strings to the right ".net" format. Cheers Bjarne Nielsen
1
1221
by: sachinko | last post by:
Context : I read command line arguments using args object and print via formatted strings. Here is the sample code, Console.WriteLine("I need to learn C# {0,9}", args, args, args, args, args, args, args, args, args, args); Is there a easy way to use the formatted strings and arrays instead of typing so much. Example i tried {0-9) to combine the formatted string but that didnt work and threw an exception - 'Input String was not in a...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5397
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4066
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
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.