RE: [SMARTY] problem displaying float

From: Date: Fri, 17 Nov 2006 16:24:55 +0000
Subject: RE: [SMARTY] problem displaying float
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13578@lists.php.net to get a copy of this message
Hi George, My test script using your example does not show anything wrong: My PHP: > <?php > > include_once "Smarty/Smarty.class.php"; > > $fee = 1.22; > settype($fee, "float"); > $fee_type = gettype($fee); > $range = explode(",","1-3"); > $rangecounter = count($range); > $rangecounter = ($rangecounter>1?$rangecounter-1:0); > $ccc_supp = floatval($rangecounter * 3); > settype($ccc_supp, "float"); > $fee2 = $fee + $ccc_supp; > > echo 'The CCC QuickPrice for this request is: $' . > sprintf("%01.2f",$fee2)."<br>$ccc_terms"; > > $rt = "Granted"; > > // create object > $smarty = new Smarty; > $smarty->assign('fcc',($rt!='Granted'?'Not available through > CCC:' . > ($rt!=''?$rt:'noreason given'):'The CCC QuickPrice for this request > is: $' > . sprintf("%01.2f",$fee2)."<br>$ccc_terms")); > > $smarty->template_dir = "D:\\web\\WAMP\\www"; > $smarty->compile_dir = "D:\\web\\WAMP\\www\\templates_c"; > // display it > $smarty->display('test.tpl'); > > ?> My Template "test.tpl" > {$fcc} The result when I use this code through the browser: > The CCC QuickPrice for this request is: $1.22 > The CCC QuickPrice for this request is: $1.22 Also for smarty you will always need a template. Thus your code should contain a $smarty->display(filename) which tell you which template you are using. Smarty is not a pretty printing tool, but a template engine. So we need variables (Assigned by $smarty->assign) and a template (Gives by $smarty->display) to create a result. Cheers, Guido -----Oorspronkelijk bericht----- Van: George Pitcher [mailto:george.pitcher@ingenta.com] Verzonden: vrijdag 17 november 2006 16:45 Aan: Smarty-General Onderwerp: RE: [SMARTY] problem displaying float > On Fri, Nov 17, 2006 at 02:10:12PM -0000, George Pitcher wrote: > [...] > > The actual code for this page is long and complex, but the > relevant snippet > > looks like: > > =========================================================== > > $fee = [web-service response (in dollars and cents)] > > settype($fee, "float"); > > $fee_type = gettype($fee); > > $range = explode(",",strim($pr)); > > $rangecounter = count($range); > > $rangecounter = ($rangecounter>1?$rangecounter-1:0); > > $ccc_supp = floatval($rangecounter * 3); > > settype($ccc_supp, "float"); > > $fee2 = $fee + $ccc_supp; > > > > $smarty->assign('ccc_fee',($rt!='Granted'?'Not available > > through CCC: > > '.($rt!=''?$rt:'no reason given'):'The CCC QuickPrice for > > this > request is: > > $'.sprintf("%01.2f",$fee2)."<br>$ccc_terms")); > > =========================================================== > > $pr is a pagerange and in the example is 9-27. extended range might be > > 1-3,9-27, which would then add $3 to the $fee variable. > > =========================================================== > > > > If I echo $fee, for my example, I get 160.44. If I echo $fee2, > I get 160.00. > > But all I've done is add '0' to the $fee variable. > > this is your third post on the topic and you still refused to show us a > single line of template code. > > now you show us a case where you trigger the error without any smarty > interference (I think we can ignore the $smarty->assign() and your > error occurs with or without it). > > so what has this to do with smarty anyway? > messju I do all my calculations in PHP and let Smarty handle the display - I thought that's what templates were all about. The problem I have is that my display via $smarty-assign() was giving me an incorrect display. I then, as usual with such an error, thought there was something wrong with the PHP code, so started echoing the output at the various steps. I still thought the problem was in PHP, but when I decided to put the process into a php file that did not include and $smarty interaction, the display was fine, which is why I'm asking the question on this list. If no-one has a solution, I'll need to think of a different way to display the price to my users. Cheers George -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

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