(might be) an interesting question

# Thread: (might be) an interesting question

1. Senior Member
Join Date
Dec 1969
Posts
380

## (might be) an interesting question

hello,<BR><BR>I want to display my percentage values fully enclosed by 0&#039;s<BR><BR>possible input values can be<BR><BR>01,00 (source=1)<BR>01,01 (source=1,01)<BR>01,10 (source=1,1<BR>11,00 (source=11)<BR>11,01 (source=11,01)<BR>11,10 (source=11,1)<BR><BR>is there an easy way to do this?<BR>in other languages you can define the amount of digits after the comma dunno if ASP has this aswell, if it has than it&#039;s an easy task with a len check and a right("0"&value,5)

2. Member
Join Date
Dec 1969
Posts
75

## RE: (might be) an interesting question

Check the technical docs in the MSDN library for the two functions: InStr() and InStrRev() (Not exactly sure that that last one is spelled perfectly, but I think you&#039;ll be able to find them.)<BR><BR>Doc.

3. Senior Member
Join Date
Dec 1969
Posts
380

## RE: (might be) an interesting question

so checking where the comma is and use a bunch of cases to add the zero&#039;s?<BR><BR>but what if the value is 5 or 35 ?<BR><BR>this needs a lot of compares then

4. Member
Join Date
Dec 1969
Posts
75

## Explain a little more...

What exactly are you trying to do? Is this information is going into a database?<BR><BR>If it&#039;s going into a database, most database programs allow you to specify the leading/trailing zeros or the exact number of digits. I do this in Access myself.<BR><BR>I guess I don&#039;t fully understand what you&#039;re trying to do...<BR><BR>Doc.

5. Senior Member
Join Date
Dec 1969
Posts
380

## RE: Explain a little more...

it&#039;s just a percentage that&#039;s being calculated and showed on screen, no need to store it into a DB.<BR><BR>the leading/trailing zero&#039;s is just to have a better layout

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## *** FORMATPERCENT function ***

In the left panel of this page, click on "VBScript Reference"<BR><BR>In the list of topics that appears, click on "Functions"<BR><BR>In the list of functions that appears, click on FORMATPERCENT.<BR><BR>(Or, if you prefer to add the % character yourself or omit it, click on FORMATNUMBER. Also note that FormatPercent expects a *fraction*--it will do the multiply by 100 for you.)<BR><BR>Either of these do everything but pad on left with zeroes.<BR><BR>SO... <BR><BR>Very tiny sneaky trick:<BR><BR>&#060;%<BR>Padded = Right ( FormatNumber( 100 + number, 2 ), 5 )<BR>%&#062;<BR>or<BR>&#060;%<BR>Padded = Right ( FormatPercent( 1 + fraction, 2) , 6 )<BR>%&#062;<BR><BR>This assumes you never have a percentage greater than or equal to 100.00%. If you might (and that would include 99.996% when rounded!), you have to get sneakier.<BR><BR>

7. Member
Join Date
Dec 1969
Posts
75

## RE: *** FORMATPERCENT function ***

Oh gosh...never seen that before. Now I know...maybe? LOL<BR><BR>Doc.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•