Page 1 of 1

generating 4 digit figures adding comma(), & dot (.)

Posted: Wed Oct 07, 2009 5:47 am
by adsegzy
Hello my Success-Oriented Friends,

Firstly, how do i code my MT_RAND() command to generate just 4 digit numbers for my PIN and confirmation.

Secondly, how do i make the number entered into one of the fields in my form to appear as currency. I want dot (.) to com after the first two digits and comma(,) after every 3 digits for it to look like this (1,234,567.89)

Regards
adsegzy

Re: generating 4 digit figures adding comma(), & dot (.)

Posted: Wed Oct 07, 2009 7:08 am
by N1gel
You could use the php rand function to generate a random 4 digit number

Code: Select all

 
$MyRandomNumber = rand(1000,9999);
 
This Function won't give you numbers less than 1000 like 0001, 0010 etc you could do a rand 0 to 9999 and then add leading 0's when required

The PHP function number_format will format your numbers with your commas and decimal place or you might want to have a look at money_format but i always prefer number_format