Formatting percentage?

Discussion in 'ASP General' started by Rob Meade, Feb 18, 2004.

  1. Rob Meade

    Rob Meade Guest

    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
    Rob Meade, Feb 18, 2004
    #1
    1. Advertising

  2. Rob Meade

    Ray at Guest

    Take a look at the formatNumber function. (I'm assuming you're using
    VBScript.)

    http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9
    http://msdn.microsoft.com/library/en-us/script56/html/vsfctformatnumber.asp

    Ray at work

    "Rob Meade" <> wrote in message
    news:KqLYb.1952$...
    > 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
    >
    >
    Ray at, Feb 18, 2004
    #2
    1. Advertising

  3. Rob Meade

    Rob Meade Guest

    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
    Rob Meade, Feb 18, 2004
    #3
  4. Rob Meade

    Rob Meade Guest

    "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 :eek:)

    Regards

    Rob
    Rob Meade, Feb 18, 2004
    #4
  5. Rob Meade

    Ray at Guest

    I never noticed the FormatPercent function. So thanks for making me notice
    that! :]

    Ray at work

    "Rob Meade" <> wrote in message
    news:MwNYb.2074$...
    > "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 :eek:)
    >
    > Regards
    >
    > Rob
    >
    >
    Ray at, Feb 18, 2004
    #5
  6. Rob Meade

    Rob Meade Guest

    "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 :eek:)

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

    Regards

    Rob
    Rob Meade, Feb 18, 2004
    #6
  7. Rob Meade

    Rob Meade Guest

    "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 :eek:)

    Regards

    Rob
    Rob Meade, Feb 18, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris

    html image percentage issue

    Chris, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    2,279
    John Saunders
    Jul 24, 2003
  2. fake ID
    Replies:
    1
    Views:
    14,351
  3. fake ID
    Replies:
    0
    Views:
    574
    fake ID
    Feb 10, 2006
  4. Stig Christiansen

    Tomcat, mod_jk, percentage character in URI?

    Stig Christiansen, Sep 8, 2004, in forum: Java
    Replies:
    0
    Views:
    424
    Stig Christiansen
    Sep 8, 2004
  5. vsoler
    Replies:
    8
    Views:
    255
    Lawrence D'Oliveiro
    Feb 24, 2010
Loading...

Share This Page