SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: % sign

  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    % sign

    What does the "%" sign do in this example.

    Code:
    var A = (JD + 1.5) % 7;
    The results are A = 0-6. Where JD is a large number like "2456123.234".

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    % is the modulo or remainder operator - %7 wil always return a result between 0 and 6 because when you subtract as many 7s as you can from a number without it ending up negative you will have somewhere between 0 and 6 left as the remainder.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you mathematically represent the % modulo or remainder operator?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    How do you mathematically represent the % modulo or remainder operator?
    The modulus operator (the % symbol) provides the remainder after dividing by the number.

    20/7 = 2 + 6/7

    20 % 7 = 6
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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