473,503 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Currency-formatted string back to decimal

KB
Hi guys,

In my DataGrid I have a column that displays decimal values as currency ( I
set the Data Formatting expression of that column to {0:C}). So the actual
string displayed in the grid looks like $2,295.99.
For each row I need to do some additional calculations based on this value,
so I need to convert it back to decimal type. But I cannot find a way to get
rid of the currency formatting and revert the value back to decimal. I tried
the following:

Convert.ToDecimal( e.Item.Cells[ColValue].Text ); // Input string was
not in a correct format
String.Format( "{0:N}", e.Item.Cells[ColValue].Text) // returns $2,295.99
String.Format( "{0:D}", e.Item.Cells[ColValue].Text) // returns $2,295.99
String.Format( "{0:G}", e.Item.Cells[ColValue].Text) // returns $2,295.99
String.Format( "{0:R}", e.Item.Cells[ColValue].Text) // returns $2,295.99

Anyone knows how to solve this.

Cheers

Kevin
Nov 18 '05 #1
2 10578
Kevin,
Just remove the $ and the , like so
e.Item.Cells[ColValue].Text.Replace("$","").Replace(",",""). The replace
just replaces them with nothing, essentially removing them from the string.

Hope this helps,
Mark FItzpatrick
Microsoft MVP - FrontPage

"KB" <a@b.com> wrote in message
news:eo******************@TK2MSFTNGP15.phx.gbl...
Hi guys,

In my DataGrid I have a column that displays decimal values as currency
( I
set the Data Formatting expression of that column to {0:C}). So the actual
string displayed in the grid looks like $2,295.99.
For each row I need to do some additional calculations based on this
value,
so I need to convert it back to decimal type. But I cannot find a way to
get
rid of the currency formatting and revert the value back to decimal. I
tried
the following:

Convert.ToDecimal( e.Item.Cells[ColValue].Text ); // Input string
was
not in a correct format
String.Format( "{0:N}", e.Item.Cells[ColValue].Text) // returns
$2,295.99
String.Format( "{0:D}", e.Item.Cells[ColValue].Text) // returns
$2,295.99
String.Format( "{0:G}", e.Item.Cells[ColValue].Text) // returns
$2,295.99
String.Format( "{0:R}", e.Item.Cells[ColValue].Text) // returns
$2,295.99

Anyone knows how to solve this.

Cheers

Kevin

Nov 18 '05 #2
Have you tried this:
http://msdn.microsoft.com/library/de...parsetopic.asp

It sounds like it should work...
Nov 18 '05 #3

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

Similar topics

2
4421
by: techy techno | last post by:
hii Experts..!! I need someone to tell me where I can get a Currency Converter like http://cconv.textor.com please can someone tell me where I can get it I need it for free + I dont need...
2
9591
by: Dalan | last post by:
This should not be an issue, but it is. I'm sure that someone knows what little piece of code is needed too persuade Access 97 to include a currency format for labels (Avery, mailing type). Have...
2
6421
by: Baybars | last post by:
New to access, but to deja.com. Looked through many posts, but can not find a good post for my problem (I believe there is, but my access level didn't allow me to understand). I have a table for...
3
2983
by: news.shaw.net | last post by:
I have a subform that contains a currency field. If I tab my way to the field, everything works as desired, a number can be entered, and when I leave the field it is rendered as a currency...
1
1649
by: Vishal | last post by:
Hello, how can we convert a value from one currency to another currency in vb.net? Is that possible? I dont want to use any hardcoded value for the exchange rate. I wont to get it online and do...
11
2936
by: Adrian | last post by:
Hi I want to use the following declarations but vb dotnet keeps complaining that currency can't be used because it private ? I have tried it in a module and in the declaration pare same error!...
2
1457
by: Chakravarthy | last post by:
Given an XML stream as below, is there any possibility to convert the same into any treditional class style with . (dots) as seperator of the nodes of the xml file... for instance ...
1
5724
by: czi02 | last post by:
Hi there; Is there anybody out there knows how to design a function or data flow on how to convert a numerical currency valu (33,163.33) into words 33Million one hundred sixty three thousand...
2
3972
vivek kushwaha
by: vivek kushwaha | last post by:
Hi guys, I need codes to convert Currency into Words. e.g. 120,500 into "One Lac. Five hundred only." in asp.net with vb.net 1.1. Please if anybody know about it. Reply me. Vivek.
0
7202
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,...
0
7084
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...
1
6991
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...
1
5013
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...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...
0
380
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...

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.