Re: calculate a varchar

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

 



I won't say you CAN'T do it (you can with eval) but you'd be WAY
better off to use some kind of exchange rate field that you can change
frequently instead of cramming formulas into the field.

"If eval is the answer, you are probably doing something wrong."

You may also want to store everything as cents (or pence) and only
insert the decimal on display to avoid rounding errors.

On Mon, December 3, 2007 9:56 am, John Taylor-Johnston wrote:
> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
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