calculate a varchar
| From: | John Taylor-Johnston | Date: | Mon, 03 Dec 2007 15:56:57 +0000 |
| Subject: | calculate a varchar | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-265412@lists.php.net to get a copy of this message | ||
Is there a calculation function?
I'm using an e-commerce shopping cart. I want to tweak the code. The author is using a varchar(100) field to store prices.
Taking advantage of there being a varchar, instead of entering a price, I would like to enter a calculation.
(24*2.2)+(24*2.2*.1) 24 is my unit price in British pounds. 2.2 is the exchange rate into Canadian dollars. etc.
The exchange rate changes frequently. Instead of recalculating and entering a new price every few days, it would be useful to enter a calculation in any price field.
I had a look at: http://ca3.php.net/manual-lookup.php?pattern=calc
http://ca3.php.net/manual-lookup.php?pattern=calculate
http://ca3.php.net/manual-lookup.php?pattern=calculation
but I see no function, although I'm sure there is one.
So how could I do this?
$price = (24*2.2)+(24*2.2*.1);
if $price is not an integer, verify if it is a calculation. If so, give me an integer and round it off to two decimal points:
$price = 58.08;
Do-able?
John