How to convert float to int in smarty

sandeep picture sandeep · Mar 9, 2011 · Viewed 19.4k times · Source

As i am new to smarty, I am not at able to convert floating number to int. Ex: 12.234 => 12 please help me if u find any solution

Answer

alex picture alex · Mar 9, 2011

Why don't you cast it before attaching it to the view. There is no reason to pass the view data that needs to be further processed.

$int = (int) $float;

$smarty->assign(array(
   'number' = $int
));

If you really must get the integer portion of a float using Smarty, try this...

{$number|string_format:"%d"}

That is like PHP's printf().