Re: [SMARTY] problem displaying float

From: Date: Fri, 17 Nov 2006 13:43:07 +0000
Subject: Re: [SMARTY] problem displaying float
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13571@lists.php.net to get a copy of this message
George Pitcher wrote: >>> The following code: >>> >>> $fee = 160.44; >>> $fee2 = $fee + 0; // I have a reason for adding zero; >>> echo $fee."<br>"; >>> echo $fee2."<br>"; >>> settype($fee, "float"); >>> echo gettype($fee); >>> > gettype($fee) before settype() gave me 'object'. > It shouldn't have! Is this a complete code example, in PHP (ie not in Smarty)? On my server the following PHP code: <?php $fee = 160.44; $fee2 = $fee + 0; // I have a reason for adding zero; echo $fee."<br>"; echo $fee2."<br>"; echo gettype($fee)."<br>"; echo gettype($fee2)."<br>"; ?> gives: 160.44 160.44 double double .. as I would have expected. I think you need to resolve this first, but I'm almost certain the problem is that the code example you've posted is not identical to the code you're trying. > I'm doing all this in the php and sending it to the template using echo. > I'm not sure what you mean by "sending it to the template using echo". It sounds like you're sending it to the browser using echo, bypassing the template altogether. A code example would help. > Initially I was sending to the template with a $smarty->assign('variable', > sprintf("%01.2f",$fee2)); > I would go with Messju's suggestion, ie use: $smarty->assign('variable',$fee2); and in the template put: {"%.2f"|sprintf:$variable} -- Mark Rogers More Solutions Ltd :: 0845 45 89 555

« previous php.smarty.general (#13571) next »