[thelist] ASP Addition question

Max Schwanekamp lists at neptunewebworks.com
Mon Jan 15 00:13:56 CST 2007

Beach Computers Web Hosting wrote:
> Ok, all is not well.
> It's rounding the result value.
> Eg: 14.95+15.00=30
> Any ideas?
> <%=CInt(Plans2.Fields.Item("PromoSetupfee").Value)+CInt(Plans2.Fields.Item("
> PromoMonthlyPrice").Value)%>

RTFM.  CInt will convert a float to an integer in VBScript a float 
getting rounded. CInt(14.95) returns 15.  CInt(14.49) returns 14.

If you want to convert numeric strings to floats, it's easiest to use 
Round() with 2 decimal places specified:
Dim a,b
a = Plans2.Fields.Item("PromoSetupfee").Value
b = Plans2.Fields.Item("PromoMonthlyPrice").Value

If Not (IsNumeric(a) and IsNumeric(b)) then
     'handle the error
End If

Response.Write(Round(a,2) + Round(b,2))


Max Schwanekamp

More information about the thelist mailing list