|
Posted by Rik on 02/07/07 17:38
One <david.hunter@gmail.com> 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=3D25;
>>
>> instead (and ensure that $history['order_total'] is also numeric).
>
> Hi Jerry - thanks much for trying.
> Same result :
> Input :
> $number_percent=3D25;
> echo "history['order_total'] is ".$history['order_total']."<br />";
> $removeit=3Dstr_replace('$' ,'', $history['order_total']);
> echo "strip the $ sign ".$removeit."<br />";
> $total =3D ($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. :-(
This works here:
<?php
$history['order_total'] =3D '$241.47';
$number_percent=3D"25";//should be without the quotes indeed, but just t=
o =
show PHP can cast this correctly
echo "history['order_total'] is ".$history['order_total']."<br />";
$removeit=3Dstr_replace('$' ,'', $history['order_total']);
echo "strip the $ sign ".$removeit."<br />";
$total =3D ($removeit * (1+($number_percent/100)));
echo "<br />total is ".$total."<br />";
?>
So I'd say there's something wrong with the exact contents of =
$history['order_total'] in your script.
What if you do this (a bit overkill):
$removeit =3D preg_replace('/[^0-9.]/','',$history['order_total']);
If this doesn't work, I'm very curious what the output of =
floatval($history['order_total'])(or floatval($removeit)) is....
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|