RE: [PHP] smary assign var
| From: | Steve Staples | Date: | Fri, 19 Nov 2010 13:56:06 +0000 |
| Subject: | RE: [PHP] smary assign var | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309570@lists.php.net to get a copy of this message | ||
On Thu, 2010-11-18 at 22:08 -0500, admin@buskirkgraphics.com wrote:
> Taking what I understand from C, I think you are looking for this equivalent
> in php.
>
> $product =
> array('reduction'=>'4','price_without_reduction'=>'22','price
> '=>'18')
> $yuzde = $product['reduction']*100;
> $yuzde = round($yuzde / $product['price_without_reduction']);
>
>
> Echo $yuzde;
> This is no reason to truncate or escape html since the strings do not
> contain them.
> I might suggest you read
> http://www.php.net/manual/en/function.round.php
> for a better understand the precision options with round.
>
>
>
>
> Richard L. Buskirk
>
>
> -----Original Message-----
> From: Tontonq Tontonq [mailto:rootdot@gmail.com]
> Sent: Thursday, November 18, 2010 6:59 PM
> To: PHP General Mailing List
> Subject: [PHP] smary assign var
>
> hi guys
> i have 2x sub value
>
> [reduction] => 4
> [price_without_reduction] => 22
> [price] => 18
>
> and i want to calculate how much i did reduction percent
>
> {assign var='yuzde' value=$product.reduction*100}
> {assign var='yuzde' value=$yuzde/$product.price_without_reduction}
>
> -{$yuzde|truncate:3:''|escape:'htmlall':'UTF-8'}%
> when i escape only 3 chars i see some products returns
> like "-18.%"
> when i escape only 2 chars
> i get e result like
> "-5.%"
>
> so is there a way to round that value to int not float?
>
>
would something like this should work... just pieced it from the smarty
site:
http://www.smarty.net/docsv2/en/language.function.math
{math assign='yuzde' equation="x + y" x=$height y=$width
format="%.2f"}
Steve
--
Steve Staples
Web Application Developer
519.258.2333 x8414