Author Topic: php not multiply  (Read 879 times)

0 Members and 1 Guest are viewing this topic.

Offline SalvisTopic starter

  • Irregular
  • Posts: 3
    • View Profile
php not multiply
« on: February 28, 2010, 08:49:31 AM »
I have code:
   <?php
$_GET
["price"]="3.13";
$_GET["currency"]="EUR";
         if(
$_GET['currency']!="LVL"){
            
$bank=simplexml_load_file('http://valutas.info/xml/'.$_GET["currency"]);
                foreach (
$bank->item->rates as $item)
                        echo 
"Kurss: ".$item->sellInCash."<br />";
                        echo 
"Cena: ".$_GET['price']."<br />";
                        
$kaka=$_GET['price']*$item->sellInCash;
                        echo 
"Reizinasana: ".$kaka."<br />";
                        
$tests1="0.7028000000000";
                        echo 
"Tests: ".$_GET["price"]*$tests1."<br />";

                    }            
            }
?>

I noticed that
$_GET['price']*$item->sellInCash
gives out 0
but $_GET["price"]*$tests1 returns all correct.
Why? Where is mistake?

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,815
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: php not multiply
« Reply #1 on: February 28, 2010, 09:08:39 AM »
I'd be inclined to believe that $item->sellInCash contains an incorrect value, or rather something that is 0 when cast to int.

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: php not multiply
« Reply #2 on: February 28, 2010, 09:19:20 AM »
And to check what's in there:
Code: [Select]
var_dump($item->sellInCash);
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline SalvisTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Re: php not multiply
« Reply #3 on: February 28, 2010, 10:12:53 AM »
var_dump($item->sellInCash);
returns:
Code: [Select]
object(SimpleXMLElement)#5 (1) { [0]=> string(5) "0.708" }
« Last Edit: February 28, 2010, 10:14:24 AM by Salvis »

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: php not multiply
« Reply #4 on: February 28, 2010, 02:52:58 PM »
How about
Code: [Select]
var_dump($item->sellInCash[0]);
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline SalvisTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Re: php not multiply
« Reply #5 on: March 01, 2010, 03:14:22 AM »
If i use
$kaka=$_GET['price']*(double)$item->sellInCash;
on line #9, it works!

Thanks all for helping.