Re: [SMARTY] problem displaying float

messju mohr <[email protected]> Fri, 17 Nov 2006 17:49:16 +0100
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
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

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php