mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-29 03:11:36 +01:00
152 lines
4.0 KiB
XML
152 lines
4.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.1 Maintainer: nobody Status: partial -->
|
|
<sect1 id="language.function.math">
|
|
<title>math</title>
|
|
<informaltable frame="all">
|
|
<tgroup cols="5">
|
|
<colspec colname="param" align="center" />
|
|
<colspec colname="type" align="center" />
|
|
<colspec colname="required" align="center" />
|
|
<colspec colname="default" align="center" />
|
|
<colspec colname="desc" />
|
|
<thead>
|
|
<row>
|
|
<entry>Nom attribut</entry>
|
|
<entry>Type</entry>
|
|
<entry>Requis</entry>
|
|
<entry>Defaut</entry>
|
|
<entry>Description</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>equation</entry>
|
|
<entry>chaîne de caractères</entry>
|
|
<entry>Oui</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>L'opération à éxécuter</entry>
|
|
</row>
|
|
<row>
|
|
<entry>format</entry>
|
|
<entry>chaîne de caractères</entry>
|
|
<entry>Non</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Le format du résultat (sprintf)</entry>
|
|
</row>
|
|
<row>
|
|
<entry>var</entry>
|
|
<entry>numeric</entry>
|
|
<entry>Oui</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Les variables de l'opération</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>chaîne de caractères</entry>
|
|
<entry>Non</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Variable de template dans laquelle la sortie
|
|
sera assignée</entry>
|
|
</row>
|
|
<row>
|
|
<entry>[var ...]</entry>
|
|
<entry>numeric</entry>
|
|
<entry>Oui</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Valeurs des variables de l'opération</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
<para>
|
|
math autorise les designers de templates à effectuer des opérations
|
|
dans le template. Toute valeur numérique peut être utilisée dans une
|
|
opération, et le résultat sera affiché à la place des balises
|
|
"equation". Les variables utilisées dans l'opération sont passées en
|
|
tant que paramètre, et peuvent être des variables de templates ou des
|
|
valeurs statiques. +, -, /, *, abs, ceil, cos,
|
|
exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt,
|
|
srans et tan sont tous des opérateurs valides. Voir la
|
|
documentation PHP pour plus d'informations sur ces fonctions
|
|
mathématiques.
|
|
</para>
|
|
<para>
|
|
Si vous spécifiez l'attribut assign, la sortie sera assignée à la variable
|
|
donnée plutôt que d'être directement affichée.
|
|
</para>
|
|
<note>
|
|
<title>Note technique</title>
|
|
<para>
|
|
math est une fonction coûteuse en terme de performances, du fait
|
|
qu'elle utilise la fonction PHP eval (). Effectuer les calculs
|
|
dans votre code PHP est beaucoup plus efficient, donc, chaque fois
|
|
que possible, effectuez vos calculs directement dans PHP et assignez
|
|
le résultat au template. Evitez coût que coût les appels
|
|
répétitifs à la fonction math, comme on pourait le faire une
|
|
une boucle section.
|
|
</para>
|
|
</note>
|
|
<example>
|
|
<title>math</title>
|
|
<programlisting>
|
|
{* $height=4, $width=5 *}
|
|
|
|
{math equation="x + y" x=$height y=$width}
|
|
|
|
SORTIE:
|
|
|
|
9
|
|
|
|
|
|
{* $row_height = 10, $row_width = 20, #col_div# = 2, assigned in template *}
|
|
|
|
{math equation="height * width / division"
|
|
height=$row_height
|
|
width=$row_width
|
|
division=#col_div#}
|
|
|
|
SORTIE:
|
|
|
|
100
|
|
|
|
|
|
{* vous pouvez utiliser des parenthèses *}
|
|
|
|
{math equation="(( x + y ) / z )" x=2 y=10 z=2}
|
|
|
|
SORTIE:
|
|
|
|
6
|
|
|
|
|
|
{* vous pouvez définir un format sprintf pour l'affichage *}
|
|
|
|
{math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
|
|
|
|
SORTIE:
|
|
|
|
9.44</programlisting>
|
|
</example>
|
|
</sect1>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|