user3417410
user3417410

Reputation: 21

Comparing numbers pulled from MySQL using If statement

Pulling 2 decimal values from MySQL and trying to use a very simple if statement:

if subtotal < minval then DO THIS else DO THIS

It always thinks subtotal is smaller even though it might not be. IsNumeric confirms both these values are numeric. If I use minval=19.99 instead of pulling from the database it works.

The code for retrieving minval looks like this:

Set rscontrol = db.Execute("select * from websitecontrol ")
minval = FormatNumber(rscontrol("minordervalue"))

Upvotes: 0

Views: 185

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200343

FormatNumber is a function for formatting a value for display. It returns a formatted string.

>>> n = 1.25
>>> WScript.Echo TypeName(n)
Double
>>> WScript.Echo TypeName(FormatNumber(n))
String

Never use formatting functions unless the result is intended for being displayed.

Change

minval = FormatNumber(rscontrol("minordervalue"))

to

minval = rscontrol("minordervalue")

If that still doesn't help you can force the value to a double using the CDbl function.

minval = CDbl(rscontrol("minordervalue"))

Beware that the function expects the decimal point as it's configured in your system's regional settings.

Upvotes: 1

Related Questions