在 、(逗号) ($value = 53,523412 后隐藏值,变为 > 53,5)


Hiding a value after a , (comma) ($value = 53,523412 to become > 53,5)

所以在我的数据库中,有用户拥有13532345学分。

例如
<?php 
  $million = $userstats['13532345'] /1000000;
  echo $million; 
?> Millions

价值为 13.532345 百万,但我想要的是 1350 万。那么如何隐藏其余的值呢?

<?php 
  echo $userstats['username']; 
  $million = $userstats['credits'] /1000000; 
?>
<a href="##" class="link">
   <?php echo $million; ?> Millions
</a>    

您可以使用 round() 函数。

echo round($million, 1);

或 number_format() 函数。

echo number_format ( $million, 1);

使用了 number_format();

$million=13.532345;
echo  number_format((float)$million, 1, '.', '');
//output=13.5

你应该使用 round() 来做这件事。

以下是链接文档中的代码片段:

echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4
echo round(3.6, 0);      // 4
echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2);    // 5.05
echo round(5.055, 2);    // 5.06
你可以

通过以下方式做到这一点——

substr($million, 0, 4); // will return first four characters

或将其四舍五入使用

round($million, 1);

或格式化它 -

number_format($million, 1, ',', ' ');