Smarty arithmetic inside how to use parentheses

Source: Internet
Author: User
Smarty arithmetic inside how to use parentheses?
PHP Code
  
   
  
   Assign ("A", $a), $smarty->assign ("B", $b), $smarty->assign ("C", $c), $smarty->display ("T.tpl"); >


HTML Code
  
   a+b:<{$a + $b}>
a/c:<{$a/$c |string_format: "%.2f"}>
(a+b)/c:<{($a + $b)/$c |string_format: "%.2f"}>


These are the programs and templates.
What can be done to achieve (A+B)/C?

------Solution--------------------
You should try to do the math in PHP. Then assign to the template.

Other than that. What's wrong with your code?
------Solution--------------------
What's wrong with the hint? PHP can then pass the results to Smarty. It's not just a matter of a few more variables or arrays.
------Solution--------------------
Look at this blog post.
------Solution--------------------
Brackets put, because there is no smarty environment. Not tested. See what other friends say.
------Solution--------------------
The arithmetic in Smarty
has been read 567 times 2006-12-4 11:14 | Personal Category: PHP
0
{* $height =4, $width = 5 *}
{Math equation= "x + y" x= $height y= $width}
OUTPUT:
9
{* $row _height = ten, $row _width = #col_div # = 2, assigned in template *}
{Math equation= "Height * width/division"
height= $row _height
Width= $row _width
division= #col_div #}
OUTPUT:
100
{* Can use parenthesis *}
{Math equation= "((x + y)/z)" X=2 y=10 z=2}
OUTPUT:
6
{* You can supply a format parameter in sprintf format *}
{Math equation= "x + y" x=4.4444 y=5.0000 format= "%.2f"}
OUTPUT:
9.44
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.