2017-06-09 26 views
0

に小数を整数に$の行の値を変更します。私がセル(<td><?= $row->price; ?></td>など)の内部でそれを実行しようとすると、テーブルレイアウトが乱れてしまいます。小数点を別々に表示するように個々のオブジェクトを設定する方法はありますか? その価格:.0000、巻:.00など。は、私はこのような何かを再作成しようとしているPHP

<table> 
    <thead> 
     <tr> 
      <th>#Rank</th> 
      <th>Name</th> 
      <th>Price</th> 
      <th>Market Cap</th> 
      <th>Volume</th> 
      <th>Supply</th> 
      <th>24h(%)</th> 
     </tr> 
    </thead> 
    <tbody> 
     <?php function compare($a, $b) { 
      return intval($a->position24) - intval($b->position24); 
     } 

     $json = file_get_contents('http://www.coincap.io/front'); 
     $data = json_decode($json); 
     usort($data, 'compare'); 
     ?> 
     <?php foreach ($data as $row) { ?> 
     <tr> 
      <td><?= $row->position24; ?></td> 
      <td><?= $row->long; ?></td> 
      <td><?= $row->price; ?></td> 
      <td><?= $row->mktcap; ?></td> 
      <td><?= $row->volume; ?></td> 
      <td><?= $row->supply; ?></td> 
      <td><?= $row->cap24hrChangePercent; ?></td> 
     </tr> 
     <?php } ?> 
    </tbody> 
</table> 

答えて

1

number_formatここにはnumber_formatサンプルがあります。

echo number_format(110000,2); // 110,000.00 
+0

私のコードにどのように適合するかの例を教えてください。 – tklein

+0

ここにあなたの価格の列 ''​​<?= number_format($ row-> price、2); ?><\td> '' –

+0

ありがとうございます。なぜそれが列を広げるかわからない。 – tklein

関連する問題