We help IT Professionals succeed at work.

# ASP rounding error on divide, INT function seems incorrect

on
weightold=351
weightnew=322
weight1b=100

percentgoal=int((weightold-weightnew)/weight1b*100)

This should clearly be exactly 29, but for some reason ASP is spitting out 28.

Thank you!
Screen-Shot-2012-03-12-at-8.00.4.jpg
Comment
Watch Question

## View Solution Only

Top Expert 2011

Commented:
<%
weightold=351
weightnew=322
weight1b=100

percentgoal=((weightold-weightnew)/weight1b*100)

response.write percentgoal

%>

Well, I am getting 29
29.JPG
Top Expert 2011
Commented:

percentgoal = CInt((weightold-weightnew)/weight1b*100)

Explanation:
CInt() - Returns an expression that has been converted to a Variant of subtype Integer.
Int() - Returns the integer portion of a number.

Here are the articles explaining the functions:
CInt:
http://msdn.microsoft.com/en-us/library/fctcwhw9%28VS.85%29.aspx

Int:
http://msdn.microsoft.com/en-us/library/t4dseb50%28v=vs.85%29.aspx
Web Developer

Commented:
I still don't understand why int("29") would return 28 and cint("29") would return 29. There is nothing to round in this case, because the value I am working with is an exact integer, no decimal points. I have used cint in the past, but then I sometimes run into problems because it only handles integers up to 32767 while int is basically unlimited.