469,323 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

convert varchar to decimal


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!
Jul 19 '05 #1
4 19676
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" <bi********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

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!

Jul 19 '05 #2
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" <bi********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

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!

Jul 19 '05 #3
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!
Jul 19 '05 #4
"Dean G" <bi********@hotmail.com> wrote in message
news:%2********************@TK2MSFTNGP11.phx.gbl.. .
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.
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by 2redline | last post: by
1 post views Thread by Woodies_46 | last post: by
2 posts views Thread by kirke | last post: by
10 posts views Thread by satishrajana | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.