A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [Problem] Rounding off to the nearest multiple of a variable

Threaded View

  1. #4
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180
    Hey,
    I see you've already seen my bugged version of the code I thought it was done, but I didn't test it too well. Here's a working version (atleast I think ), but I haven't tested it with negative values though. I suggest you use this code as it's easier to read and to adjust for use with negative values.
    code:

    var srtN = 23;
    var oldN = 234;
    var newN;
    //--
    if (oldN%srtN<srtN/2) {
    newN = oldN-(oldN%srtN);
    } else {
    newN = oldN-(oldN%srtN)+srtN;
    }
    trace(newN);



    SaphuA
    Last edited by SaphuA; 01-20-2005 at 06:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center