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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

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

Post 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
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

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

Post 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
Post Reply