嗨我在php中得到这样的值:0.3350我想只显示3个数字,比如0.335。
代码:
<?php
$url = 'http://ir.euroinvestor.com/ServiceEngine/api/xml/reply/RequestStockDataBundle?apiversion=1&solutionID=2614&customerKey=OpgPowerVenturesPlc&instrumentTypes=Listing';
$xml = simplexml_load_file($url) or die("feed not loading");
$Ask = $xml->Data->InstrumentEntry[0]->Ask;
echo $Ask;
?>
我试图添加:
echo round($Ask, 2);
但是只得到0
答案 0 :(得分:0)
将值转换为float,然后round(),如:
$Ask = (float) $xml->Data->InstrumentEntry[0]->Ask;
echo round($Ask, 3);