Jump to content

pad a number


poe

Recommended Posts

Use the [url=http://www.php.net/sprintf]sprintf()[/url] function.

[code]<?php
for($i=0;$i<10;$i++)
  echo sprintf("%05d",rand(1,1000)).'<br>';
?>[/code]

The above code will print ten random numbers between 1 and 1000 padded to 5 characters with zeros.

Ken
Link to comment
https://forums.phpfreaks.com/topic/27943-pad-a-number/#findComment-127813
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.