Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smarty convert string to number

I need to do deviding:

{math equation="x/y" x=$x y=$y} // $x = '2', $y = '3'

How to convert strings to numbers exactly in Smarty, coz I don't have access to proprietary code of CMS? Thanx!

UPD: Smarty version: 2.6.18

like image 695
Sergey Kudryashov Avatar asked May 16 '14 12:05

Sergey Kudryashov


1 Answers

If it's already assigned to a variable, say $var, you can set the type of a variable like this:

{$converted = settype ($var, 'integer')}

You don't have to use the $converted value, but if you don't assign it, the bool will show up in your page.

or you could try

{$variable|intval}
like image 175
Guns Avatar answered Sep 27 '22 20:09

Guns