Question

I have this xml file - http://gamebattles.majorleaguegaming.com/ps4/call-of-duty-ghosts/team/ngx2-gaming/stats.xml

here which I am outputting the element "winPercentage" as seen below

<?php
$url="http://gamebattles.majorleaguegaming.com/ps4/call-of-duty-ghosts/team/ngx2-gaming/stats.xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
?>
<?php echo $xml->currentStats->winPercentage; ?>

The question is, how can I change the output of 0.667 to 66.7 instead? I assume it would involve multiplying it by 100, but have no idea how to achieve this.

Thank you for your time and help!

Was it helpful?

Solution

Answer is below for anyone else looking for the same thing

Replace:

<?php echo $xml->currentStats->winPercentage; ?>

With

<?php echo (float)$xml->currentStats->winPercentage *100; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top