FORMATING NUMBERS IN ASP

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default FORMATING NUMBERS IN ASP

    I have the results of a stored procedure coming back in an asp successfully however it seems to be rounding up the number of decimal places I have. Here is an example of how my results are coming back and how I need them to come back:
    Currentl
    Pub Name Cal Price Copies Re
    Belfast Tele 0 1165
    0.01 1165 1.16
    0.0111 45 etc....
    0.02 699 etc...
    0.0274 187 etc...
    0.06 159 etc...
    0.1 23468 etc...
    0.135 89 etc...
    0.18 100 etc...
    0.3 100 etc...
    0.3313 100 etc...
    0.375 56489 etc...
    0.5 1568 etc...
    How I want it to look like: (Want Cal Price field to have four decimal places
    Pub Name Cal Price Copies Re
    Belfast Tele 0.0000 1165
    0.0100 1165 1.16
    0.0111 45 etc....
    0.0200 699 etc...
    0.0274 187 etc...
    0.0600 159 etc...
    0.1000 23468 etc...
    0.1350 89 etc...
    0.1800 100 etc...
    0.3000 100 etc...
    0.3313 100 etc...
    0.3750 56489 etc...
    0.5000 1568 etc...

    My asp code is as follows:
    CAN ANYONE HELP ME ACCOMPLISH THI
    <
    lsDate = Request.Form("date"

    set dbconn = server.CreateObject("ADODB.Connection"
    set lrstLog = server.CreateObject("ADODB.Recordset"

    dbConn.Open Application("connectionString"
    'dbconn.Open "DSN=WEBaccounts;uid=patrice;pwd=gillan;PageTimeou t=5;
    'dbconn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=;Initial Catalog=cms_out;Data Source=sunaccserv

    lrstLog.Open "ByWeekEnding '" & lsDate & "'", dbconn,

    %><
    lrstLog.movefirs
    %><table border=1 width="500"><tr bgcolor=#F9F9C7><th>Publication Name</th><th>Price</th><th>Copies</th><th>Revenue</th></tr><tr><
    dim varThisPub, varLastPub, sumCopy, sumRevenu
    sumCopy=
    sumRevenue=
    varLastPub = "
    varThisPub = "

    do until lrstLog.EO
    varThisPub = lrstLog("publication_name"

    'Check to see if this record has the same publication name as the last on
    if varThisPub = varLastPub then 'don't need to rewrite pub nam
    response.write "<td>&nbsp;</td>
    else 'this is a new pub name. If it's not the first publication, write a summary row for the previous record, then write row to start new publication name
    if varLastPub <> "" the
    response.write "<td><b><Font size = 4>Totals</Font></b></td>
    response.write "<td>&nbsp;</td>
    response.write "<td><b><font color = blue size = 4><div align=right>" & sumCopy & "</div></font></b></td>
    response.write "<td><b><font color = blue size = 4><div align=right>" & sumRevenue & "</div></font></b></td>
    response.write "</tr><tr style=page-break-before:always>&nbsp;
    response.write "</tr><tr bgcolor=#F9F9C7><th>Publication Name</th><th>Price</th><th>Copies</th><th>Revenue</th></tr><tr>
    end i

    response.write "<td><b>" & lrstLog("publication_name") & "&nbsp;</td></b>

    'reset total
    sumCopy =
    sumRevenue =

    end i

    sumCopy = sumCopy + lrstLog("Copies") 'you may need to use CINT(1stlog("Copies")) to get this to work- depends on your database and data types
    sumRevenue = sumRevenue + lrstLog("Rev")

    response.write "<td>" & lrstLog("calculated_price") & "</td>
    response.write "<td><div align=right>" & lrstLog("Copies") & "</div></td>"
    response.write "<td><div align=right>" & lrstLog("Rev") & "</div></td>"
    response.write "</tr><tr>"
    varLastPub = varThisPub
    lrstLog.movenext
    'Next
    loop
    'write the final totals row
    response.write "<td><b><Font size = 4>Totals</Font></b></td>"
    response.write "<td>&nbsp;</td>"
    response.write "<td><b><font color = blue size = 4><div align=right>" & sumCopy & "</div></font></b></td>"
    response.write "<td><b><font color = blue size = 4><div align=right>" & sumRevenue & "</div></font></b></td>"
    response.write "</tr><tr>&nbsp;"
    response.write "</tr></table>"
    lrstLog.Close
    set lrstLog = nothing
    dbConn.Close
    set dbConn = nothing
    %>
    Stephen Cairns Guest

  2. Similar Questions and Discussions

    1. Need CSS formating help
      I'm new to CSS and I am used to HTML tables but I have a new client who needed a site in CSS. (I used one of the Dreamweaver tempates) After using...
    2. Date Formating
      Hello I would like to format a date in the DataGrid to be 3.3.2004 and not with the time (default?) 3.3.2004 00:00:00! <asp:DataGrid...
    3. Formating strings and numbers
      Is there a way to format strings and numbers (beside dates)? I was looking for some method to diplay number values in format with commas and zeros...
    4. [PHP] formating date
      > -----Original Message----- Try this: $mailed=$row; $payment=$row; $ID=$row;
    5. Formating (HELP)
      I have a second drive in my system, and I'm running Windows XP Home Edition (NTFS). The problem is when I try to format it says it can't and that I...
  3. #2

    Default Re: FORMATING NUMBERS IN ASP

    Stephen Cairns wrote:
    > I have the results of a stored procedure coming back in an asp
    > successfully however it seems to be rounding up the number of decimal
    > places I have. Here is an example of how my results are coming back
    > and how I need them to come back: - Currently
    > Pub Name Cal Price Copies Rev
    > Belfast Tele 0 1165 0
    > 0.01 1165 1.165
    > How I want it to look like: (Want Cal Price field to have four
    > decimal places)
    > Pub Name Cal Price Copies Rev
    > Belfast Tele 0.0000 1165 0
    > 0.0100 1165 1.165
    I don't see any rounding. Trainling zeros are being truncated but no
    rounding is occurring
    >
    When writing the data to the page, use the FormatNumber function to control
    the decimal places displayed. For example:

    response.write "<td>" & _
    FormatNumber(lrstLog("calculated_price"),4,true,fa lse,true) & "</td>"

    Look up the function in online help to see what the arguments mean.
    [url]http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en[/url]

    Bob Barrows


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139