c# - Enter a code branch every ten percent till 100 percent -


i can think of convoluted methods loops , nested loops solve problem i'm trying more professional that.

my scenario need enter section of code every ten percent isn't quite working expected. entering code every percent due code lack knowledge know how change it.

int currentpercent = math.truncate((current * 100m) / total);  //avoid divide 0 error  if (currentpercent > 0) {    if (isdivisible(100, currentpercent))    {      ....my code works fine other coming in many times    }  } 

helper referenced above trouble is:

private bool isdivisible(int x, int y) {   return (x % y) == 0; } 

so works should. mod eliminates currentpercent of 3 1 & 2 pass when don't want true value until currentpercent = 10 , not again till 20...etc.

thank , apologies elementary question

i might misunderstand you, seems you're trying extremely simple more complex needs be. this?

for (int = 1; <= 100; i++) {     if (i % 10 == 0)     {         // here, can want - happen          // every ten iterations ("percent")     } } 

or, if entire code enters somewhere else (so no loop in scope), important part i % 10 == 0.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -