Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
How to add leading zeros
Old 01-23-2007, 12:34 PM How to add leading zeros
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
I want to pad my numbers with leading zeros, for a total of three places. For example, I want:

"18" to be "018"
"118" to be "118"

What is the best way to do this in ASP?

Thank you in advance!

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-23-2007, 03:16 PM Re: How to add leading zeros
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, I never did asp, but a quicke google search gaved me that:
http://lists.evolt.org/archive/Week-...12/120001.html

Quote:
<tip author="Anthony Baratta" subject="Padding Numbers with leading Zeros
in ASP">

I used to run numbers I wanted to pad through a function that checked to
see if the number was less than 9 or 99, and padded with leading zeros
accordingly. The other day I stumbled across a more simple and straight
forward way. (Believe it or not it was at the Microsoft MSDN site.)

_Padding with a Leading Zero the Day and Month_

strDay = Right("00" & CStr(Day(Now())),2)
strMonth = Right("00" & CStr(Month(Now())),2)

If you want two leading zeros for hundreds just change the 2 to a 3.

Piece of pie.

</tip>
--
Anthony Baratta
President
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-23-2007, 05:57 PM Re: How to add leading zeros
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Thank you , I think that will do the trick!

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 01-23-2007, 08:20 PM Re: How to add leading zeros
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
In ASP Classic, you can use the Format function, like you would in Excel:

Format(18, "00000.0")

Arguments might be reversed - I haven't done this for a while.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 01-24-2007, 12:01 PM Re: How to add leading zeros
bbutton's Avatar
Experienced Talker

Posts: 43
Name: Bill Button
Location: Reading,UK
Trades: 0
Hi,

Not sure format will do this, but here is what I have used.

NumberOfLeadingZeros = 3
MyNumber = 18

MyNumberWithLeadingZeros = right(string(NumberOfLeadingZeros,"0") & cstr(MyNumber),NumberOfLeadingZeros)

response.write MyNumberWithLeadingZeros
__________________
Bill Button

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
bbutton is offline
Reply With Quote
View Public Profile Visit bbutton's homepage!
 
Old 01-27-2007, 12:55 AM Re: How to add leading zeros
Novice Talker

Posts: 9
Trades: 0
bbuttons way will work the best. There are otherways of handeling the problem, but you should be checking your string and formatting it anyways, so best to handle the problem before inserting.
urbndk is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to add leading zeros
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22505 seconds with 12 queries