473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

numbers in php

anfetienne
424 256MB
Hi,

i've looked through the hp manual and cant find a function for this... is it possible to echo out double figures instead of single in php? for exmaple

Expand|Select|Wrap|Line Numbers
  1.     for($i=00;$i<23;$i++){
  2.         echo '<option value="'.$i .'">'.$i .'</option>';
  3.     }
  4.  
this lists as 1,2,3,4,5,6,7,8,9,10 and i want it to be 01,02,03,04,05,06,07,08,09

is this possible?
Apr 26 '10 #1

✓ answered by Atli

Hey.

Check out the printf function. You can have it format the values you pass it in a number of ways, including the way you are asking.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. printf("%03d\n", 7);
  3. // This prints: 007
  4. ?>

4 1279
Atli
5,058 Expert 4TB
Hey.

Check out the printf function. You can have it format the values you pass it in a number of ways, including the way you are asking.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. printf("%03d\n", 7);
  3. // This prints: 007
  4. ?>
Apr 26 '10 #2
anfetienne
424 256MB
Thanks Atli... that's perfect!
Apr 26 '10 #3
anfetienne
424 256MB
i tested it outside my loop and it outputs correctly but once inside my loop it still outputs single digits..... strange
Apr 26 '10 #4
anfetienne
424 256MB
i fixed it... here is my solution.... THANKS AGAIN

Expand|Select|Wrap|Line Numbers
  1.     for($i=0;$i<23;$i++){
  2.         echo '<option value="'; printf("%02d\n", $i); echo '">'; printf("%02d\n", $i); echo '</option>';
  3.     }
  4.  
Apr 26 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
7
by: Gerard Flanagan | last post by:
All would anyone happen to have code to generate Cutter Numbers: eg. http://www1.kfupm.edu.sa/library/cod-web/Cutter-numbers.htm or is anyone looking for something to do?-) (I'm under...
10
by: LuTHieR | last post by:
Hi, I'm reading a string of numbers from a file (using Borland C++ Builder 6), and I'm doing it like this: first I use FileRead to store all the data in the file to a char* variable (appropriately...
7
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.