473,473 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Formatting percentage?

Hi all,

I have a recordset iterating through and dumping out to the screen a series
of percentages, using the precision 5 and numericscale 2 etc.

When I dump them to the page some of the number are missing a trailing
zero - ie,

4.7

What I would very much like to do is add this back on - is there an easy way
to format this with a huge load of If...Then's to produce the same affect?

Thanks in advance for any help,

Regards

Rob
Jul 19 '05 #1
7 5419
Take a look at the formatNumber function. (I'm assuming you're using
VBScript.)

http://www.microsoft.com/downloads/d...6-1C4099D7BBB9
http://msdn.microsoft.com/library/en...rmatnumber.asp

Ray at work

"Rob Meade" <ro********@NO-SPAM.kingswoodweb.net> wrote in message
news:Kq*********************@news-text.cableinet.net...
Hi all,

I have a recordset iterating through and dumping out to the screen a series of percentages, using the precision 5 and numericscale 2 etc.

When I dump them to the page some of the number are missing a trailing
zero - ie,

4.7

What I would very much like to do is add this back on - is there an easy way to format this with a huge load of If...Then's to produce the same affect?

Thanks in advance for any help,

Regards

Rob

Jul 19 '05 #2
Ok - this gets a bit more odd now....

Currently I have a count which goes into this recordset.....each row gets a
number - a whole number (an integer)...

When I've updated all of these rows, lets say they look like this :

row1 5
row2 3
row3 3
row4 2
row5 1

I iterate through, and divide each one of these by the total of all of them,
so in the above :

row1 5/14 = 0.35714285714
row2 3/14 = 0.21428571428
row3 3/14 = 0.21428571428
row4 2/14 = 0.14285714285
row5 1/14 = 0.07142857142

now, at the moment after this division I also then multiply these by 100 -
to give me a percentage (this might be changed in a bit)...

row1 = 35.714285714
row2 = 21.428571428
row3 = 21.428571428
row4 = 14.285714285
row5 = 7.142857142

These get stored back into the recordset and pulled out in a sec, the
recordset has a adNumeric data type, with the 5 and 2 set for the precision
/ numericscale etc..so I'm assuming they end up something like this now :

row1 = 35.71
row2 = 21.43
row3 = 21.43
row4 = 14.29
row5 = 7.14

When *these* display to the page they'll all be fine, no 7.1 or anything
like that, but as these are not preset by me I cannot guarantee this, so I
wanted to find a way to make sure that after the decimal place there are
always 2 figures.

I stumbled across FormatPercent - its name suggested this might be what I
want.

I've had mixed results using it, from an error if I try this :

<%=FormatPercent(RS("Relevance"),2,0,0)%>

To getting the numbers multipled by a further 100 if I CONVERT the
RS("Relevance") value first, so far the only conversion that seems to give
me what I want is CCur (currency) - Int's are out, as are Doubles...

So, assuming now that I go with CCur - not that I was overly happy with this
solution, but I now need to drop my * 100 above, and thus I 'assume' I get
this :

row1 5/14 = 0.36
row2 3/14 = 0.21
row3 3/14 = 0.21
row4 2/14 = 0.14
row5 1/14 = 0.07

Now when they display they are always WHOLE percentages - ie 36%, 21% etc -
I never see a 21.72, or 1.01 ..

If anyone can give me some help with this I would be most grateful.

Best regards

Rob
Jul 19 '05 #3
"Ray at <%=sLocation%> [MVP]" wrote...
Take a look at the formatNumber function. (I'm assuming you're using
VBScript.)


Hi Ray,

Many thanks for your reply and info, please ignore my other post which was
posted before I read your posted reply.

That has resolved the problem nicely :o)

Regards

Rob
Jul 19 '05 #4
"Rob Meade" <ro********@NO-SPAM.kingswoodweb.net> wrote in message
news:AP*********************@news-text.cableinet.net...
Ok - this gets a bit more odd now....

Currently I have a count which goes into this recordset.....each row gets a number - a whole number (an integer)...

When I've updated all of these rows, lets say they look like this :

row1 5
row2 3
row3 3
row4 2
row5 1

I iterate through, and divide each one of these by the total of all of them, so in the above :

row1 5/14 = 0.35714285714
row2 3/14 = 0.21428571428
row3 3/14 = 0.21428571428
row4 2/14 = 0.14285714285
row5 1/14 = 0.07142857142

now, at the moment after this division I also then multiply these by 100 -
to give me a percentage (this might be changed in a bit)...

row1 = 35.714285714
row2 = 21.428571428
row3 = 21.428571428
row4 = 14.285714285
row5 = 7.142857142

These get stored back into the recordset and pulled out in a sec, the
recordset has a adNumeric data type, with the 5 and 2 set for the precision / numericscale etc..so I'm assuming they end up something like this now :

row1 = 35.71
row2 = 21.43
row3 = 21.43
row4 = 14.29
row5 = 7.14

When *these* display to the page they'll all be fine, no 7.1 or anything
like that, but as these are not preset by me I cannot guarantee this, so I
wanted to find a way to make sure that after the decimal place there are
always 2 figures.

I stumbled across FormatPercent - its name suggested this might be what I
want.

I've had mixed results using it, from an error if I try this :

<%=FormatPercent(RS("Relevance"),2,0,0)%>

To getting the numbers multipled by a further 100 if I CONVERT the
RS("Relevance") value first, so far the only conversion that seems to give
me what I want is CCur (currency) - Int's are out, as are Doubles...

So, assuming now that I go with CCur - not that I was overly happy with this solution, but I now need to drop my * 100 above, and thus I 'assume' I get
this :

row1 5/14 = 0.36
row2 3/14 = 0.21
row3 3/14 = 0.21
row4 2/14 = 0.14
row5 1/14 = 0.07

Now when they display they are always WHOLE percentages - ie 36%, 21% etc - I never see a 21.72, or 1.01 ..


Rob,
I'm not exactly sure what you are trying to accomplish. It sounds like you
want to store the percentage value in the database with 2 decimal places.
And it sounds like you are concerned that if the value is something like
7.10, then it will be displayed on the page as 7.1. So, to get around that
problem, use the FormatNumber function when you want to display the result,
and append the percentage symbol to the end:

<%=FormatNumber(RS("Relevance"),2,0,0) & "%" %>

In this case, if RS("Relevance") has a value of 7.1, it should be displayed
as 7.10, and then the % will be printed at the end.

Hope this helps.
Peter Foti


Jul 19 '05 #5
"Peter Foti" wrote ...
It sounds like you want to store the percentage value in the database with 2 decimal places. And it sounds like you are concerned that if the value is something like
7.10, then it will be displayed on the page as 7.1.


Thats it in a nut shell :o)

Thanks for your reply Peter, all working now :o)

Regards

Rob

Jul 19 '05 #6
I never noticed the FormatPercent function. So thanks for making me notice
that! :]

Ray at work

"Rob Meade" <ro********@NO-SPAM.kingswoodweb.net> wrote in message
news:Mw*********************@news-text.cableinet.net...
"Ray at <%=sLocation%> [MVP]" wrote...
Take a look at the formatNumber function. (I'm assuming you're using
VBScript.)


Hi Ray,

Many thanks for your reply and info, please ignore my other post which was
posted before I read your posted reply.

That has resolved the problem nicely :o)

Regards

Rob

Jul 19 '05 #7
"Ray at <%=sLocation%> [MVP]" wrote ...
I never noticed the FormatPercent function. So thanks for making me notice that! :]


hehe - its probably useful in some abstract instance somewhere :o)

Regards

Rob
Jul 19 '05 #8

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

Similar topics

7
by: shawnk | last post by:
Hello Everyone How do you format format numbers right-justified using Console.WriteLine(), i.e I need to line up numbers in vertical columns and the MSDN documentation is pretty poor Here is the...
3
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign...
1
by: CK | last post by:
Newbie question. This has to be simple but what's the easiest way to take a string and format it as currency? What about a percentage? Thanks In Advance, Chris
0
by: fake ID | last post by:
Since you can't search for these symbols used in asp.net "<%#" or '<%=' I thought i'd post this to make things a little easier to find. Potential search word combinations: -lessthan Percentage...
5
by: James Conrad StJohn Foreman | last post by:
Have found http://www-128.ibm.com/developerworks/db2/library/techarticle/lyle/0110lyle.html which is quite helpful, but doesn't quite tell me what I want. I have a table, advertising_spend with...
1
by: (PeteCresswell) | last post by:
I am storing a percentage in a Double field. No problem formatting it for presentation (e.g. .33456 shows as 33.456%). But when the user edits the field, they have to type in the decimal...
2
by: Smiley | last post by:
In a program I'm creating, I'm trying to calculate a percentage. However, for some reason the calculation is only coming out to 1 decimal place, and I know there's more. Using this code: ...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
5
by: Aswanth | last post by:
I'm Using Asp.Net with C# & Working with SSRS 2005 for Generating Reports.. The Following Expression I'm using in Reports to Show the Percentage of Particular Items in REPORT.. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.