donglu2008 2011-02-11 23:07
浏览 18
已采纳

小于1mb时的PHP数字格式

Hope someone can figure this one out.

I'm using this to display the filesizes of several files in a folder...

number_format (round (filesize($currentfile) /1048576)) . "mb"

...which displays my file names like this:

27mb
35mb
10mb

etc.

But, if the filesize is less than 1mb, it displays onscreen as:

0mb

How can I modify the PHP so that if it encounters a 250k file for example, it shows displays as ".25mb"?

Thanks in advance.

  • 写回答

5条回答 默认 最新

  • duandao8607 2011-02-11 23:11
    关注

    Well you just need to check if it is below 1MB and handle it differently.

    number_format (filesize($currentfile) / 1048576, (filesize($currentfile) < 1048576 ? 2 : 0)) . "mb"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题