dongmi1221 2017-05-09 23:34
浏览 126

如何格式化数字来定义千位分隔符?

I am a php noob (very) and i got following code:

<?echo getPointsColor($row["fld_points"])?>

Currently the number 1234 in the database is shown as 1,234, but i would like to have it 1234 (without as thousand seperator).

I found:

$english_format_number = number_format($number, 0, '.', '');

This would make it 1234 instead of 1,234

BUT i don't know how to change my code (first code above) to make it work. Can someone post me how the correct codechange would like like?

Info, here is the the function:

function getPointsColor($points_to_color)
{
    $myp = intval($points_to_color);

    if($myp <= 0)
        $myp = "<font color='#a71212\'>".number_format($myp,'\'')."</font>";
    else
        $myp = "<font color='#4ea712\'>".number_format($myp,'\'')."</font>";

    return $myp;
}
  • 写回答

2条回答 默认 最新

  • dqf98772 2017-05-09 23:47
    关注

    You can do it like this:

    $english_format_number = number_format($number, 2, '.', ',');
    

    Reference

    The third parameter sets the decimal separator, the fourth sets the thousands separator.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?