mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-06 15:21:37 +01:00
150 lines
4.9 KiB
XML
150 lines
4.9 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>Nombre del Atributo</entry>
|
|
<entry>Tipo</entry>
|
|
<entry>Requerido</entry>
|
|
<entry>Default</entry>
|
|
<entry>Descripción</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>equation</entry>
|
|
<entry>string</entry>
|
|
<entry>Si</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>La ecuación a ejecutar</entry>
|
|
</row>
|
|
<row>
|
|
<entry>format</entry>
|
|
<entry>string</entry>
|
|
<entry>No</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>El formato del resultado (sprintf)</entry>
|
|
</row>
|
|
<row>
|
|
<entry>var</entry>
|
|
<entry>numeric</entry>
|
|
<entry>Si</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Valor de la variable de la ecuación</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>string</entry>
|
|
<entry>No</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Variable de template cuya salida sera asignada</entry>
|
|
</row>
|
|
<row>
|
|
<entry>[var ...]</entry>
|
|
<entry>numeric</entry>
|
|
<entry>Si</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>Valor de la variable de la ecuación</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
<para>
|
|
math permite diseñar ecuaciones matemáticas dentro del template.
|
|
Cualquier variable numérica del template puede ser usada en
|
|
ecuaciones, y el resultado es mostrado en lugar de la etiqueta.
|
|
Las variables usadas en ecuaciones son pasadas como parámetros,
|
|
que pueden ser variables de template o valores estáticos.
|
|
+, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min,
|
|
pi, pow, rand, round, sin, sqrt, srans y tan son todos los
|
|
operadores validos. Verifique la documentación de PHP para mas
|
|
información acerca de estas funciones matemáticas.
|
|
</para>
|
|
<para>
|
|
Si usted proporciona el atributo especial "assign", la salida de la
|
|
función matemática será atribuido a esta variable de template en
|
|
vez de ser mostrada en el template.
|
|
</para>
|
|
<note>
|
|
<title>Nota Técnica</title>
|
|
<para>
|
|
math es una función de muy alto rendimiento debido a que se
|
|
puede usar con la función eval() de PHP.
|
|
Hacer las matemáticas en PHP es mucho mas eficiente, asi en
|
|
cualquier momento es posible hacer calculos matemáticos en PHP
|
|
asignarlos a una variable y lanzar los resultados al template.
|
|
Defínitivamente evite llamadas repetitivas de funciones
|
|
matemáticas, dentro de los ciclos section.
|
|
</para>
|
|
</note>
|
|
<example>
|
|
<title>math</title>
|
|
<programlisting>
|
|
{* $height=4, $width=5 *}
|
|
|
|
{math equation="x + y" x=$height y=$width}
|
|
|
|
SALIDA:
|
|
|
|
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#}
|
|
|
|
SALIDA:
|
|
|
|
100
|
|
|
|
|
|
{* Usted puede usar parentesis *}
|
|
|
|
{math equation="(( x + y ) / z )" x=2 y=10 z=2}
|
|
|
|
SALIDA:
|
|
|
|
6
|
|
|
|
|
|
{* Usted puede asignar un parámetro de formato en sprintf *}
|
|
|
|
{math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}
|
|
|
|
SALIDA:
|
|
|
|
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
|
|
-->
|