Solved

ASP rounding error on divide, INT function seems incorrect

Posted on 2012-03-12
3
158 Views
Last Modified: 2012-03-13
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
0
Comment
Question by:bbdesign
3 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37712639
<%
weightold=351
weightnew=322
weight1b=100

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

response.write percentgoal

%>

Well, I am getting 29
29.JPG
0
 
LVL 15

Accepted Solution

by:
pateljitu earned 500 total points
ID: 37712845
Please use CInt() instead of Int() function, and your code should be changed to:

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
0
 

Author Comment

by:bbdesign
ID: 37713984
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.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now