Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > convert varchar to decimal

Reply
Thread Tools

convert varchar to decimal

 
 
Dean G
Guest
Posts: n/a
 
      10-11-2004

I need to compare two values. one from a text field 'bid' and the other
from a field in an sql server database 'maxbid'.

The problem is the column in the database has decimal as its data type
and i'm getting a type mismatch. does anyone know how to convert 'bid'
into decimal from varchar? the field datatype doesnt necessarily have
to be decimal although i need two decimal places so it cant be an int.

Thanks,
Dean

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      10-11-2004
Are you trying to do this comparison at the database level or in your code?
If database, show query. If code, show code.

Ray at home

"Dean G" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> I need to compare two values. one from a text field 'bid' and the other
> from a field in an sql server database 'maxbid'.
>
> The problem is the column in the database has decimal as its data type
> and i'm getting a type mismatch. does anyone know how to convert 'bid'
> into decimal from varchar? the field datatype doesnt necessarily have
> to be decimal although i need two decimal places so it cant be an int.
>
> Thanks,
> Dean
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
 
Manohar Kamath
Guest
Posts: n/a
 
      10-11-2004
You can use CSng to convert it into a Single, but then make sure the
variable is not empty/numeric before you do the conversion.

If Trim(myVar) <> vbNullString And IsNumeric (myVar) Then
myVarSng = CSng(myVar)
End If

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com


"Dean G" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> I need to compare two values. one from a text field 'bid' and the other
> from a field in an sql server database 'maxbid'.
>
> The problem is the column in the database has decimal as its data type
> and i'm getting a type mismatch. does anyone know how to convert 'bid'
> into decimal from varchar? the field datatype doesnt necessarily have
> to be decimal although i need two decimal places so it cant be an int.
>
> Thanks,
> Dean
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Dean G
Guest
Posts: n/a
 
      10-12-2004
thanks manohar that did the trick, i still had to change it from decimal
to float before it would work though, if anyone has the same problem.

Dean



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Chris Hohmann
Guest
Posts: n/a
 
      10-12-2004
"Dean G" <(E-Mail Removed)> wrote in message
news:%23I8%23n$%(E-Mail Removed).. .
> thanks manohar that did the trick, i still had to change it from decimal
> to float before it would work though, if anyone has the same problem.


Decimals are weird little creatures in VBScript. Unlike integers, longs,
etc... they are not a recognized variant subtype. Let me qualify that by
saying VarType() will return 14, but TypeName() will fail. Try
TypeName(decimalvalue) and you will receive the following error:

"Variable uses an Automation type not supported in VBScript"

So when performing arithmetic operations, one is forced to convert
decimals to a supported subtype using functions such as CInt,CDbl, and
most importantly CCur. The reason I emphasize CCur is that the currency
subtype is in fact a decimal with 4 point precision, masquerading as a
supported VBScript variant subtype. The problem with CInt is that you
lose data on the conversion and the problem with CDbl is that they
represent approximations of a number. It's beyond the scope of this
thread but basically it has to do with the fact that computers represent
numbers (and everything else) in binary. As such if a number cannot be
represented as the sum of the powers of 2, an approximation is made.

Response.Write 1 - .94
6.00000000000001E-020.99

So when dealing with decimals of precision less than or equal to 4, CCur
is a good choice.


 
Reply With Quote
 
 
 
Reply

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
decimal.Decimal formatting python@lists.fastmail.net Python 0 07-19-2010 12:32 PM
how to convert from Decimal('1.23456789') to Decimal('1.234') valpa Python 11 03-24-2009 07:11 AM
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



Advertisments