Calculations in ASP Classic and FormatNumber the result

大城市里の小女人 提交于 2019-12-11 03:35:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!