Click to See Complete Forum and Search --> : how to add 0's to a number
gilgalbiblewhee
Apr 23rd, 2008, 06:35 PM
I want to add 0s to a number.
Let's say I have 5, I have to add 4 digits like this:
00005
If I have 17 I have to add 3 digits like this:
00017
manavo11
Apr 23rd, 2008, 07:39 PM
str_pad (http://www.php.net/str_pad) :)
<?php
$num = 9;
echo str_pad($num, 5, "0", STR_PAD_LEFT);
$num = 17;
echo str_pad($num, 5, "0", STR_PAD_LEFT);
?>
lintz
Apr 23rd, 2008, 07:40 PM
$num = 5;
$zeros = "0000";
echo $zeros.$num;
$num = 17;
$zeros = "000";
echo $zeros.$num;
penagate
Apr 23rd, 2008, 10:49 PM
$r = sprintf('%05d', $number);
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.