最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if value is multiple of 10 - Stack Overflow

programmeradmin1浏览0评论

I want to check if a value is a multiple of a certain number, for example, multiples of 10, but I also want to be able to change it to whatever I want.

if (directWinner == 10){

}

I want to check if a value is a multiple of a certain number, for example, multiples of 10, but I also want to be able to change it to whatever I want.

if (directWinner == 10){

}
Share Improve this question edited Mar 25, 2013 at 15:02 Emil Ivanov 37.6k12 gold badges76 silver badges90 bronze badges asked Mar 25, 2013 at 14:58 user1937021user1937021 10.8k25 gold badges85 silver badges150 bronze badges 3
  • 2 This does have absolutely nothing to do with jQuery. – Bergi Commented Mar 25, 2013 at 15:00
  • 5 Amazing. Staggering. doxdesk.com/img/updates/20091116-so-large.gif – Matt Ball Commented Mar 25, 2013 at 15:00
  • -1 all the answers, not enough jQuery. – BinaryTox1n Commented Mar 25, 2013 at 15:04
Add a comment  | 

3 Answers 3

Reset to default 18

You'd use the modulus operator for that :

if (directWinner % 10 === 0){
    directWinner = 20;
}

Added a small dose of jQuery for no good reason at all ?

$.modu = function(check, against) {
    return check % against === 0;
}

if ( $.modu(directWinner, 10) ) {
    directWinner = 20;
}

You'd use the modulo operator % for that:

var certainNumber = 10;
if (directWinner % certainNumber === 0) {
    // directWinner is a multiple of certainNumber
}

Use the modulo operator (assuming positive integers) :

if (directWinner % 10 === 0) {
    ...
}
发布评论

评论列表(0)

  1. 暂无评论