473,385 Members | 1,375 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,385 software developers and data experts.

Number formating: 1 -> '01'

Hi,

I am tryin to format a number from, for example, 1 to '01'. How is this done? Cheers

Burnsy
Jul 17 '05 #1
4 2130
.oO(mr_burns)
I am tryin to format a number from, for example, 1 to '01'. How is this done?


http://www.php.net/sprintf

Micha
Jul 17 '05 #2
While the city slept, mr_burns (bi******@yahoo.co.uk) feverishly typed...
I am tryin to format a number from, for example, 1 to '01'. How is
this done? Cheers


printf("<p>num with 2 digits (leading zero): %02d</p>", $num);

Demo'd here: http://www.nigenet.org.uk/stuff/formatNum.php

Hope that helps,
Nige

--
Nigel Moss
http://www.nigenet.org.uk
Mail address not valid. ni***@DOG.nigenet.org.uk, take the DOG. out!
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #3
mr_burns wrote:
Hi,

I am tryin to format a number from, for example, 1 to '01'. How is this done? Cheers

Burnsy


From the PHP docs:

" kennyc at horizondigital dot com
14-Jun-2002 07:57
ONELINE LEADING ZERO ADDER: I kept getting frustrated by php's weak number
formatting functions and using the recursive leading zero adders that I've seen
in other people code, so here's my quick and easy oneliner for adding leading
zero's to any number:

Two digit space:
substr($num+100,1);
0=00
5=05
23=23
3.14=03.14

Four digit space:
substr($num+10000,1);
0=0000
5=0005
23=0023
256=0256
4096=4096
98.6=0098.6

You may want to check first to be sure that your number dosen't already exceed
it's character size!"

quite ingenious I might add.. I actually wrote this a couple of hours ago, just
forgot to send it... sorry for the delay...

--
Michael Austin.
Consultant - NOT Available.
Donations STILL welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #4
.oO(Michael Austin)
From the PHP docs:

" kennyc at horizondigital dot com
14-Jun-2002 07:57
ONELINE LEADING ZERO ADDER: [...]


Nice little hack, but not necessary anymore.

Micha
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jamie Fryatt | last post by:
I have a querystring that passes through the value 001 for example, the form on the receiving page need to display that number but with 1 added to it. i have dim strnum strnum =...
2
by: Nadav | last post by:
Hi, How can I use C# to print a number in hexadecimal e.g. printf(" %x "); or print 15 ( decimal ) as 'F' (hexa) Can a number be printed as binary as-well? Thanks in advance, Nadav.
4
by: Eric | last post by:
Hi, In my application I need to round a number to 3 decimal places. I am using the Math.Round method which works fine. The problem I am running into is when the number has no decimals like 5...
6
by: Bill | last post by:
Hi I am having trouble trying to format a number string to two decimal places if the number ends in a 0 It formats fine otherwise. For example if PrincRepay is 78.20 it will display it as 78.2...
0
by: rodrigo guerra | last post by:
where i can change the code formating that visual studio does in the code.... like if i type: if ( ) { .... } visual studio changes to:
0
by: SimonZ | last post by:
Hi, I set the globalization settings to: <globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8" culture="en-GB" uiCulture="en" /> Everything is just fine, only...
3
by: Smiley | last post by:
Hi, I know how to do confitional formating in Excel by clicking the wizard. Is this possible in MS Access ? If so, please directly where to look. I found example but nothing as to how to do it....
12
tolkienarda
by: tolkienarda | last post by:
hi all I am working on a content management service and i need some help keeping formating. what i am doing is recreating my site in an admin side and all of the articles on the site will...
1
by: Shawn Northrop | last post by:
I just read an article on kirupa.com about incorporating mySQL and PHP with flash. I am dynamically loading conent into a flash movie and am not sure how to format. In my php code i have: $y = "";...
0
by: Fonix | last post by:
I'm trying to make table border with pyExcelerator. As i can see there is only cell formating!? If i'm wrong pls tell me what is method to make more then one cell to have same format, other then...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.