mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-29 03:11:36 +01:00
149 lines
4.8 KiB
XML
149 lines
4.8 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<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>Nome Attributo</entry>
|
|
<entry>Tipo</entry>
|
|
<entry>Obbligatorio</entry>
|
|
<entry>Default</entry>
|
|
<entry>Descrizione</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>equation</entry>
|
|
<entry>stringa</entry>
|
|
<entry>sì</entry>
|
|
<entry><emphasis>nessuno</emphasis></entry>
|
|
<entry>l'equazione da eseguire</entry>
|
|
</row>
|
|
<row>
|
|
<entry>format</entry>
|
|
<entry>stringa</entry>
|
|
<entry>no</entry>
|
|
<entry><emphasis>nessuno</emphasis></entry>
|
|
<entry>formato del risultato (sprintf)</entry>
|
|
</row>
|
|
<row>
|
|
<entry>var</entry>
|
|
<entry>numerico</entry>
|
|
<entry>sì</entry>
|
|
<entry><emphasis>nessuno</emphasis></entry>
|
|
<entry>valore di una variabile dell'equazione</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>stringa</entry>
|
|
<entry>no</entry>
|
|
<entry><emphasis>nessuno</emphasis></entry>
|
|
<entry>variabile del template cui verrà assegnato il risultato</entry>
|
|
</row>
|
|
<row>
|
|
<entry>[var ...]</entry>
|
|
<entry>numerico</entry>
|
|
<entry>sì</entry>
|
|
<entry><emphasis>nessuno</emphasis></entry>
|
|
<entry>valore di una variabile dell'equazione</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
<para>
|
|
La funzione math permette al progettista di effettuare equazioni
|
|
matematiche nel template. Qualsiasi variabile numerica del template
|
|
può essere utilizzata nell'equazione; il risultato verrà stampato
|
|
al posto del tag. Le variabili usate nell'equazione vengono passate
|
|
come parametri, che possono essere variabili del template o valori
|
|
statici. +, -, /, *, abs, ceil, cos, exp, floor, log, log10, max,
|
|
min, pi, pow, rand, round, sin, sqrt, srans e tan sono tutti operatori
|
|
validi. Controllate la documentazione di PHP per ulteriori informazioni
|
|
su queste funzioni matematiche.
|
|
</para>
|
|
<para>
|
|
Se fornite lo speciale attributo "assign", l'output della
|
|
funzione verrà assegnato a questa variabile del template,
|
|
invece di essere stampato in output.
|
|
</para>
|
|
<note>
|
|
<title>Nota tecnica</title>
|
|
<para>
|
|
math è una funzione costosa in termini di prestazioni, a
|
|
causa dell'uso che fa della funzione php eval(). Fare i
|
|
calcoli matematici in PHP è molto più efficiente, quindi,
|
|
quando possibile, fate i calcoli in PHP ed assegnate i
|
|
risultati al template. Evitate decisamente chiamate
|
|
ripetitive alla funzione math, ad esempio in cicli section.
|
|
</para>
|
|
</note>
|
|
<example>
|
|
<title>math</title>
|
|
<programlisting>
|
|
{* $height=4, $width=5 *}
|
|
|
|
{math equation="x + y" x=$height y=$width}
|
|
|
|
OUTPUT:
|
|
|
|
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#}
|
|
|
|
OUTPUT:
|
|
|
|
100
|
|
|
|
|
|
{* potete usare le parentesi *}
|
|
|
|
{math equation="(( x + y ) / z )" x=2 y=10 z=2}
|
|
|
|
OUTPUT:
|
|
|
|
6
|
|
|
|
|
|
{* potete indicare un parametro format in formato sprintf *}
|
|
|
|
{math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
|
|
|
|
OUTPUT:
|
|
|
|
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
|
|
-->
|