Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > String (Currency) to Decimal Conversion

Thread Tools

String (Currency) to Decimal Conversion

Martyn Fewtrell
Posts: n/a
Hi there

I'm sure there is a straight forward answer to this but I haven't quite got

If I have a String in Sterling Currency Format and try to convert this to a
Decimal (for arithmetic purposes it works fine).

Sample code (VB.Net):

Dim UK As New CultureInfo("en-GB")
SA.Text = (S1.Text * S2.Text).ToString("c", UK)

Dim decSterling as Decimal = SA.Text

(where S1, S2 and SA are text boxes)

If I run the identical code for Dollars this fails with the exception can't
convert String "$...." to Decimal

Sample Code (VB.Net):

Dim US As New CultureInfo("en-US")

DA.Text = (D1.Text * D2.Text).ToString("c", US)

Dim decDollars as Decimal = DA.Text

(where D1, D2 and DA are text boxes)

Why can I convert a string to decimal when using (Sterling) but not $

Thanks for your help

Martyn Fewtrell Removed)

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: String to char and decimal number conversion Chris Rebert Python 2 01-11-2011 10:41 AM
Conversion: double IEEE 754 => decimal ASCII-String olliH VHDL 1 01-23-2009 12:18 PM
Error: Cannot convert Decimal("0.0000") to Decimal Vitaliy Python 1 05-29-2008 10:36 AM
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why? Gilbert Fine Python 8 08-01-2007 01:58 AM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM