Re: [SMARTY] problem displaying float

From: Date: Fri, 17 Nov 2006 16:49:16 +0000
Subject: Re: [SMARTY] problem displaying float
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13579@lists.php.net to get a copy of this message
smarty displays what you assign. nothing more nothing less. again: the fact that you use smarty does not make this a smarty issue. maybe you have some locale settings that disturb your float-conversions? like this braindead behaviour of php: setlocale(LC_ALL, "de_DE.UTF-8"); $foo = 10001/100; echo $foo, "\n"; echo floatval("$foo"), "\n"; gives on my system: 100,01 100 On Fri, Nov 17, 2006 at 04:12:19PM -0000, George Pitcher wrote: > Guido and Peggy, > > > So what are you using to print the variable in the template? > > > > e.g. > > {$variable} > > > > Or {php}echo $variable{/php} > > > $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','The CCC QuickPrice for this request is: > $'.sprintf("%01.2f",$fee2)."<br>$ccc_terms"); > > > > > Or what? > > > > And do you use any modifier for the variable, or do you just use the > > variable as assigned to? > > > maybe you did not assign $fee properly/at all... > > > > There should be a line of code in your php-script like: > > > $smarty->assign('fee',$fee); > > > Within your template you then state {$fee} or as messju recommended > > {"%.2f"|sprintf:$fee} > > The latter modifies a string to get the proper number of floating values > > (or however these are called).... > > All is handled in PHP before assignation. I'm only asking $smarty to display > my variable. > > I've been using Smarty for 3 years now - across over 20 websites and this is > the first real hassle I've encountered. > > Anyway, I'm off for the weekend now. > > Cheers > > George

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