user132546 user132546 - 4 months ago 259
Smarty Question

smarty convert string to Integer/Float

I have some string value, like

$value = "123.45";
.

Since I have to compare this
$value
with Integer, I need to convert
$value
's type to float.

How can I convert String to Integer/Float in smarty language?

Thanks.

Answer

you can use php's functions floatval / intval in smarty:

{$value = $value|floatval}
{$value = $value|intval}

Multiplying by 1 would also work:

{$value = $value*1}