2016-04-27 8 views
0

私は私のウェブサイトの上にティッカーを持っています。jsonデコードの結果に別の数字を追加するにはどうすればいいですか?

今の結果が表示され2.14

私が呼んでいるAPIは、私に余分な数字を与えますが、その表示されません。

結果はここ2.147

を表示する必要がありますが、私が働いているコードの一部です。

$obj = json_decode($json); 
$symbol[$i] = $obj->results[0]->symbol; 
$open[$i] = number_format($obj->results[1]->open, 2, '.', ','); 
$high[$i] = number_format($obj->results[1]->high, 2, '.', ','); 
$low[$i] = number_format($obj->results[1]->low, 2, '.', ','); 
$close[$i] = number_format($obj->results[1]->close, 2, '.', ','); 
$gap[$i] = number_format($obj->results[1]->close - $obj->results[0]->close, 2, '.', ','); 
$percent[$i] = number_format($obj->results[1]->close/$obj->results[0]->close, 2, '.', ','); 

10進数の後に3桁目を表示させるにはどうすればよいですか?

+0

' '2 'に' 3 'を変更

は、ここでのドキュメントですか? – frz3993

+1

ドキュメントを読む:http://php.net/manual/en/function.number-format.php – Sammitch

答えて

0

の値(小数点以下2桁を表す)を3(小数点以下3桁)に置き換えます。

基本的に2番目の属性showは、結果の書式を設定する小数点以下の桁数です。 http://php.net/manual/en/function.number-format.php

これはあなたのコードがどのように見えるかです:: `をnumber_format()で

$obj = json_decode($json); 
$symbol[$i] = $obj->results[0]->symbol; 
$open[$i] = number_format($obj->results[1]->open, 3, '.', ','); 
$high[$i] = number_format($obj->results[1]->high, 3, '.', ','); 
$low[$i] = number_format($obj->results[1]->low, 3, '.', ','); 
$close[$i] = number_format($obj->results[1]->close, 3, '.', ','); 
$gap[$i] = number_format($obj->results[1]->close - $obj->results[0]->close, 3, '.', ','); 
$percent[$i] = number_format($obj->results[1]->close/$obj->results[0]->close, 3, '.', ','); 
+1

私はあなたを愛し、ありがとう – party

+0

私は助けることができる嬉しい:) –

関連する問題