问题
After my previous post (in which everyone was really helpful - thanks) ive now hit another issue... Calculations and to FormatNumber the result.
I have 3 fields in SQL that i need to do a simple calculation with then the result needs to have FormatNumber applied to it..
the fields are
"OverallFee" , "WIPFee" , "RenderedFee" - all are numeric
throughout the table they populate fine with the below.
<td width="100" align="center" class="style1"><% If Not IsNull(rs("OverallFee")) Then Response.Write ("£" + FormatNumber(rs("OverallFee"),0)) End If %></td>
<td width="100" align="center" class="style1"><% If Not IsNull(rs("RenderedFee")) Then Response.Write ("£" + FormatNumber(rs("RenderedFee"),0)) End If %></td>
<td width="100" align="center" class="style1"><%=rs("WIPFee")%></td>
Now I need to do a calculation -
("OverallFee"/100) * "WIPFee" - "RenderedFee"
I've tried
<td width="50" align="center" class="style1"><%=((rs("OverallFee")/100)*rs("WIPFee")-rs("RenderedFee"))%></td>
It should work but I'm getting
Microsoft VBScript runtime error '800a000d' - Type mismatch "
on that line and I'm stuck...
Am I doing it right... is there an easier way?
回答1:
Try to convert your data to long CLng or double CDbl
<%
calc = 0 'Or a text to display
If Not IsNull(rs("RenderedFee")) And Not IsNull(rs("OverallFee")) And Not IsNull(rs("WIPFee")) Then
calc = (CLng(rs("OverallFee"))/100)*CLng(rs("WIPFee"))-CLng(rs("RenderedFee"))
End If
%>
<td width="50" align="center" class="style1"><%=calc%></td>
来源:https://stackoverflow.com/questions/33280063/calculations-in-asp-classic-and-formatnumber-the-result