smarty convert string to number

Sergey Kudryashov picture Sergey Kudryashov · May 16, 2014 · Viewed 29.8k times · Source

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

Answer

Guns picture Guns · May 16, 2014

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}