开发者

How to convert float to int in smarty

开发者 https://www.devze.com 2023-02-15 13:03 出处:网络
As i am new to smarty, I am not at 开发者_StackOverflow中文版able to convert floating number toint.

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


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


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


this might work give a try

(string)((int)$float)

that too check this link

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


This can be done:

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

You'll need to assign the return value of settype, bool, else the value will be displayed in the UI.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号