Re: calculate a varchar

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;

You may want to look at eval().

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux