Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert float to int in smarty

Tags:

php

smarty

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

like image 359
sandeep Avatar asked Mar 09 '11 07:03

sandeep


3 Answers

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().

like image 53
alex Avatar answered Nov 14 '22 10:11

alex


Also you should be able doing this: {$variable|intval}

like image 5
Luca Reghellin Avatar answered Nov 14 '22 08:11

Luca Reghellin


this might work give a try

(string)((int)$float)

that too check this link

http://www.smarty.net/forums/viewtopic.php?p=61912

like image 1
Harish Avatar answered Nov 14 '22 10:11

Harish