Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

math

Nome Attributo Tipo Obbligatorio Default Descrizione
equation stringa nessuno l'equazione da eseguire
format stringa no nessuno formato del risultato (sprintf)
var numerico nessuno valore di una variabile dell'equazione
assign stringa no nessuno variabile del template cui verrà assegnato il risultato
[var ...] numerico nessuno valore di una variabile dell'equazione

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.

Se fornite lo speciale attributo "assign", l'output della funzione verrà assegnato a questa variabile del template, invece di essere stampato in output.

Nota tecnica

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.

Example 8.14. math

{* $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

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 12 plus 19? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk