duanji8615 2013-06-10 16:48
浏览 138
已采纳

没有逗号的PHP数字格式

I want to display the number 1000.5 like 1000.50 with 2 decimal places and no commas/thousands separators.

I am using number_format to achieve this:

number_format(1000.5, 2);

This results 1,000.50. The comma (,) separator appended in thousand place which is not required in the result.

How can I display the number with a trailing zero and no comma?

  • 写回答

5条回答 默认 最新

  • douba5540 2013-06-10 16:50
    关注

    See the documentation for number_format: http://php.net/number_format

    The functions parameters are:

    string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

    So use:

    number_format(1000.5, 2, '.', '');
    

    Which means that you don't use any (= empty string) thousands separator, only a decimal point.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)