|
Posted by One on 02/08/07 18:28
On Feb 7, 1:00 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> One wrote:
> > On Feb 7, 11:34 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> $number_percent is a string containing 25, not the numeric value 25.
> >> When you use a string in a calculation it's numeric value is zero.
>
> >> Try
> >> $number_percent=25;
>
> >> instead (and ensure that $history['order_total'] is also numeric).
>
> > Hi Jerry - thanks much for trying.
> > Same result :
> > Input :
> > $number_percent=25;
> > echo "history['order_total'] is ".$history['order_total']."<br />";
> > $removeit=str_replace('$' ,'', $history['order_total']);
> > echo "strip the $ sign ".$removeit."<br />";
> > $total = ($removeit * $number_percent);
> > echo "<br />total is ".$total."<br />";
>
> > Output :
> > history['order_total'] is $241.47
> > strip the $ sign 241.47
> > total is 0
>
> > This is bonkers - I'm *sure* I have done this type of thing in the
> > past without issue. :-(
>
> Rik caught one and I caught the other (I missed the dollar sign).
>
> Both are string in your setup. Use floatval() to convert your
> $history['order_total'] to a floating point number.
Hi guys - thanks SO much for your replies - it is still not working -
I'm using the floatval properly but it is returning a zero :
Input :
echo "history['order_total'] is ".$history['order_total']."<br />";
$removeit=str_replace('$' ,'', $history['order_total']);
echo $removeit;
$floatandremove = floatval($removeit);
echo "<br />floatandremove is ".$floatandremove;
exit;
Output :
history['order_total'] is $241.47
241.47
floatandremove is 0
This is getting crazy!
Navigation:
[Reply to this message]
|