
This should be easy..
I want to truncate (not round) a number to return a value with no decimals.... the opposite of the mod() function, if you want to think of it that way...<BR><BR>For instance:<BR><BR>5 divided by 2 = 2.5<BR>desired answer is 2<BR><BR>2 divided by 3 = 0.666666667<BR>desired answer is 0.<BR><BR>Should I just use the split function?<BR><BR><BR>Thanks in advance!

Use INT()
That'll give you what you want

RE: This should be easy..
Don't know if there's a function that does this for you, but you could always subtract the modulus from your number.

RE: This should be easy..
Use:<BR><BR>52<BR><BR>The backslash does integer division.

*DUH* INT( ) is the obvious answer

Because you know I HAVE to give 2 more cents...
INT() is definitely the intuitive answer... but integer division using the "\" symbol is approximately 34 times faster than first doing a floating point divide AND an integer evaluation.<BR><BR>Example benchmark: <BR><BR>using int(5/2) .44 seconds<BR>using 52 .16 seconds<BR><BR><BR>:)

Curious
I ran your test, just to see...<BR><BR>I had run the test out to 10 millionths of a second, and both tests ran exactly the same speed, although nowhere near the times you got.<BR><BR>I think also if you're concerned about time, you shouldn't divide at all if there's a better solution. Division is the biggest dog on the processor...<BR><BR>5 * .5 is quicker than 5 / 2<BR><BR>Just wondering how you ran these tests. Don't get militant on me!

RE: Curious
I don't get militant unless someone's asking the wrong question. :) Your question is perfectly reasonable.<BR><BR>You can't run a test like this on one sample, wouldn't you agree? Especially considering that the timer code you are using on your PC is not going to be accurate to 10/millionths of a second anyway... :)<BR><BR>The times I quoted were for 100000 iterations.<BR><BR>The code I used to briefly test is below. By the way, after reading your message, I added a third test to the code (int(5*.5)). The results were as follows:<BR><BR>Time1 was 0.171875 (this is the 52)<BR>Time2 was 0.4375 (this is the int(5/2))<BR>Time3 was 0.3789063 (this is the int(5 * .5))<BR><BR><BR><BR>Anyway, without further ado, here is the sample code.<BR><BR><%<BR> dim x, st, et1, et2, r, s<BR><BR> st = timer<BR> for x = 1 to 100000<BR> r = 52<BR> next<BR> et1 = timer  st<BR><BR> st = timer<BR> for x = 1 to 100000<BR> s = int(5/2)<BR> next<BR> et2 = timer  st<BR><BR> response.write "Time1 was " & et1 & "<br>Time2 was " & et2<BR><BR>%><BR>

Very Interesting
Yes, I didn't run the one division. I ran a loop out to 100, which explains why my numbers were nowhere near yours. I had to run the seconds out that far for changes to even register.<BR><BR>Well, I learned something new today (**** it. You're not supposed to learn anything new on a Friday. Beer will take care of that). Looks like I'll use the from now on.<BR><BR>Although, we also found from this test that multiplying is a bit quicker than division. (it significantly drops when the Int() function is removed).<BR><BR>Thanks!
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

