This should be easy..

Results 1 to 9 of 9

Thread: This should be easy..

  1. #1
    LeeAnnie Guest

    Default 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!

  2. #2
    Steve Cimino Guest

    Default Use INT()

    That&#039ll give you what you want

  3. #3
    Kasper Guest

    Default RE: This should be easy..

    Don&#039t know if there&#039s a function that does this for you, but you could always subtract the modulus from your number.

  4. #4
    BalletChick Guest

    Default RE: This should be easy..

    Use:<BR><BR>52<BR><BR>The backslash does integer division.

  5. #5
    LeeAnnie Guest

    Default *DUH* INT( ) is the obvious answer

    Thanks, Steve!

  6. #6
    BalletChich Guest

    Default Because you know I HAVE to give 2 more cents...

    INT() is definitely the intuitive answer... but integer division using the "\" symbol is approximately 3-4 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>:)

  7. #7
    Join Date
    Dec 1969

    Default 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&#039re concerned about time, you shouldn&#039t divide at all if there&#039s 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&#039t get militant on me!

  8. #8
    BalletChick Guest

    Default RE: Curious

    I don&#039t get militant unless someone&#039s asking the wrong question. :) Your question is perfectly reasonable.<BR><BR>You can&#039t run a test like this on one sample, wouldn&#039t 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>&#060;%<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 & "&lt;br&gt;Time2 was " & et2<BR><BR>%&#062;<BR>

  9. #9
    Steve Cimino Guest

    Default Very Interesting

    Yes, I didn&#039t 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&#039re not supposed to learn anything new on a Friday. Beer will take care of that). Looks like I&#039ll 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