Showing posts with label 4 digit. Show all posts
Showing posts with label 4 digit. Show all posts

Saturday 28 June 2014

JS get random Numbers

function getRandom(length) {
 var rand = Math.floor(Math.pow(10, length-1) + Math.random() * 9 * Math.pow(10, length-1));
 return rand;
}

Wednesday 25 June 2014

PHP number format 4 digits [duplicate]

Method I

echo str_pad( "3", 4, "0", STR_PAD_LEFT );
Input $s_number = "3"; Output: 0003

Method II

$s_number = '12';
printf("%04d", $s_number);
Input $s_number = "12"; Output: 0012