Re: [SMARTY] problem displaying float

[email protected] (Mark Rogers) Fri, 17 Nov 2006 17:56:03 +0000
Newsgroups php.smarty.general
Organization Quarella Ltd
Message-ID <[email protected]>
George Pitcher wrote:
> Guido and Peggy,
>   
>> So what are you using to print the variable in the template?
>      $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");
>   

None of the above displays anything; you assign a value to the Smarty,
but don't show the call to $smarty->display() or (and this is what both
I and others have asked for) what you put in the template. For the sake
of argument I'll assume your template just says
    {$ccc_fee}

I think it's clear that the value being assigned is wrong, so this isn't
a Smarty issue, but a PHP one. This list gets more than its fair share
of off-topic PHP queries hence some reluctance to assist in non-Smarty
problems. However, I'll make some suggestions then bow out of the topic
(I'll assist off-list if you're really stuck).

Why are you using lots of settype() calls? Is that the result of some
hacks to try and resolve this problem? It's very rare that settype
should really be needed anywhere.

What does the following code give you?

	$fee = [web-service response (in dollars and cents)]
	var_dump($fee);
	$range = explode(",",strim($pr));
	$rangecounter = count($range);
	$rangecounter = ($rangecounter>1?$rangecounter-1:0);
	$ccc_supp = $rangecounter * 3;
	var_dump($range, $rangecounter, $ccc_supp);
	$fee2 = $fee + $ccc_supp;
	var_dump($fee2, sprintf("%01.2f",$fee2));

Note that I use var_dump as that tells you both the value and the type in one.


> All is handled in PHP before assignation. I'm only asking $smarty to display
> my variable.
>   

The implication, which there's been nothing to suggest to the contrary
here, is therefore that the variable is wrong before it gets to Smarty.
Unless, that is, you're doing something in Smarty other than just
displaying what its sent, such as formatting code. That's why seeing the
relevant part of the template would help.

> I've been using Smarty for 3 years now - across over 20 websites and this is
> the first real hassle I've encountered.
>   

I'm 90% sure this is nothing to do with Smarty, but I'm quite open to
being proved wrong on that.

-- 
Mark Rogers
More Solutions Ltd :: 0845 45 89 555