dqsw7529 2017-09-18 12:05
浏览 29
已采纳

将7位数字浮动到小数点左边

I need to get numbers in order but need them to be like this

0000001
0000002
0000003
etc.

I have tried a few different lines of code and nothing works. It always puts the 7 placed to the right of the decimal like this 1.0000000, 2.0000000

Here is what I currently have

$i = 0000001;
while ($i != 0001001){
$i = number_format("$i",7);
echo $i."<br />";
$i++;
}
  • 写回答

1条回答 默认 最新

  • dongshukou0240 2017-09-18 12:07
    关注

    You can use sprintf:

    sprintf("%07d",$i);
    

    So instead of number_format:

    $i = 0000001;
    while ($i != 0001001) {
        $i = sprintf("%07d", $i);
        echo $i . "<br />";
        $i++;
    }
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)