Ask a Question related to ASP Database, Design and Development.
-
Stephen Cairns #1
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> </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> </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>
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") & " </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> </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> "
response.write "</tr></table>"
lrstLog.Close
set lrstLog = nothing
dbConn.Close
set dbConn = nothing
%>
Stephen Cairns Guest
-
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... -
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... -
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... -
[PHP] formating date
> -----Original Message----- Try this: $mailed=$row; $payment=$row; $ID=$row; -
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... -
Bob Barrows [MVP] #2
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.165I don't see any rounding. Trainling zeros are being truncated but no> 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
rounding is occurringWhen 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



Reply With Quote

