晕 round()会将数字四舍五入的啊.

解决方案 »

  1.   

    四舍五入也是格式化的一部分!<?php
    $n = '1234567890.5555555555';
    $t = strtok($n, '.');
    $s = '';
    while($c = substr($t, -3)) {
      $t = substr($t, 0, -3);
      $s = (strlen($c)==3 ? ',' : '').$c . $s;
    }
    $s .= '.'. strtok('');
    echo $s;
    ?>
    1,234,567,890.5555555555
      

  2.   

    php里小数后好象最多也就支持到5位吧……
      

  3.   

    谢谢各位大大,
     xuzuning(唠叨)大大的写法可以做到,有没有简单一点的啊.嘿嘿.
      

  4.   

    这个够简单吧echo preg_replace("/(\d{1,3})(?=(\d{3})+\.)/","$1,",$num);
      

  5.   

    你还用number_format函数
    如果你想保留两位小数,可以把你的数字 -0.005
    例如
    123456789.5569你想要得结果是
    123,456,789.55
    你可以
    number_format(123456789.5569-0.005,2,"",",");如果你只想保留整数可以
    number_format(123456789.5569-0.5);