Having problems with casting string from database to float
Posted: Tue Apr 07, 2009 5:28 pm
It seems so simple. I'm trying to evaluate whether a number stored in a MySQL db is smaller than zero. The number is stored a 'text' value in the db, but is representing a float, specifically, a percentage. Here's my code:
MODULE_SHIPPING_USPS_HANDLING = .5 in the db.
I've tried casting it as floatval(MODULE_SHIPPING_USPS_HANDLING), (float)MODULE_SHIPPING_USPS_HANDLING, adding a float to it, and many others but to no avail. The code acts as if it's a string (I think) and $cost_handling always evaluates to the false side of the operator ($handling is added correctly to $cost to produce a decimal value).
What am I doing wrong?
Code: Select all
$handling = MODULE_SHIPPING_USPS_HANDLING;
$cost_handling = $handling < 0 ? $cost + ($handling * $cost) : $cost + $handling;
I've tried casting it as floatval(MODULE_SHIPPING_USPS_HANDLING), (float)MODULE_SHIPPING_USPS_HANDLING, adding a float to it, and many others but to no avail. The code acts as if it's a string (I think) and $cost_handling always evaluates to the false side of the operator ($handling is added correctly to $cost to produce a decimal value).
What am I doing wrong?