You are here: Re: multiplication math not working ? « PHP Programming Language « IT news, forums, messages
Re: multiplication math not working ?

Posted by Jerry Stuckle on 02/07/07 16:34

One wrote:
> hi group -
>
> I had this in a function - so I've just moved this out of the function
> for readabilty.
>
> Can someone please tell me WHY does this not return the result of :
> n1 times n2
>
> As I said - I took it out of the function just for readability :
> In my php file :
>
> $number_percent="25";
> echo "history['order_total'] is ".$history['order_total']."<br />";
> echo "number_percent is ".$number_percent."<br />";
> $total=(($history['order_total'])*$number_percent);
> echo "total is ".$total."<br />";
>
> And here is the output in the browser :
> history['order_total'] is $241.47
> number_percent is 25
> total is 0
>
> WHY ? Any advice or pointers would be much appreciated!
>

$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).


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация