|
Posted by Jerry Stuckle on 02/07/07 18:00
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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|