Hi can i ask for help pls.

I have this xml values from a given xml file
i wanted to retrieved it from there and when
I was trying to retrieved it and echo it out
it shows the correct value together with the
decimal values. But when the i used the value
for the computation and echo out the result
it only shows the whole number so it omitted the
decimal values and didn't include it in the
computation.

I was wandering if you guys has an idea
on what is happening on this process or
if anyone already encountered this problem
before.

thank you hope to hear from you guys .
this is my code


this the php code the bottom part is the computation that im talking about

<?php
$xml = simplexml_load_file("test.xml");
	
$xml->getName();
$prod_price=0;
$price = 0.00;
$prod_num = 0;
$apple = 0.00;
$orange = 0.00;
$pear = 0.00;
$lemon = 0.00;

foreach($xml->products->children() as $child)
  {
	$products_node = $xml->products->product[$prod_price]->attributes();
	
	foreach($products_node as $p_attrib)
	{
		 
		
		
		$prod_num++;
		if ($prod_num<3)
		{
		$p_name = $prod_num." -  ".$p_attrib;
			
			{
			if($prod_num == 1)
			
				{
					$object = $p_attrib;
				}
			elseif($prod_num==2)
				{
				 	$price = $p_attrib;	
				}	
				
				else
				{
					//do nothing	
				}
			}
		
		
		
		    
		}
		else
		{
		 
		}


	}
	$prod_price++;
	
	 
	 //this is a double declaration variable
	 $$object = $price;
	 
	 echo "<li>".$object. "=". $price."</li>";
	 
	
	 
  $prod_num=0;
 
  echo $price + $price;

  
  }
   
?>

and this is the xml file that im talking about

<?xml version="1.0" encoding="utf-8"?>

<results>
<transactions>
	<transaction customer="Janakan" object ="apple" />
	<transaction customer="david" object ="orange" />
	<transaction customer="Janakan" object ="pear" />
	<transaction customer="James" object ="orange" />
	<transaction customer="James" object ="lemon" />
	<transaction customer="david" object ="orange" />
	<transaction customer="david" object ="pear" />
	<transaction customer="david" object ="apple" />
	<transaction customer="James" object ="apple" />
	<transaction customer="Janakan" object ="lemon" />
	<transaction customer="Nancy" object ="pear" />
	<transaction customer="Kate" object ="orange" />
	<transaction customer="Janakan" object ="apple" />
	<transaction customer="Nancy" object ="lemon" />
	<transaction customer="Kate" object ="orange" />
	
		
</transactions>
<products>
<product object="apple" price="3.99"/>
<product object="lemon" price="1.50"/>
<product object="pear" price="5.00"/>
<product object="orange" price="2.30"/>
</products>
</results>

variable must be be formatted as float using the floatval thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.