jquery - javascript math calculation case -


update: can see 2 votes closing problem because not clear need. here need: need once value on 1,100,000 price calculated accordingly, example points between 1,100,001 , 1,200,000 price $220, points between 1,200,001 , 1,300,000 $240, etc, without limit, example 4,500,001 , 4,600,000 price $720.

i need javascript caluclation goes this:

1-500,000 points $30/100,000 points

500,001-999,999 points $25/100,000 points

1,000,000+ points $20/100,000 points

i have case switch check value , correct sum want know how can example if user enter 4,500,000 points or random value more 1,100,000. have currently:

  if (number(amountofpoints) > number(0)) {     switch (true) {         case (amountofpoints > 0 && amountofpoints <= 100000):             {                 price = 30;                 break;             }         case (amountofpoints > 100000 && amountofpoints <= 200000):             {                 price = 60;                 break;             }         case (amountofpoints > 200000 && amountofpoints <= 300000):             {                 price = 90;                 break;             }         case (amountofpoints > 300000 && amountofpoints <= 400000):             {                 price = 120;                 break;             }         case (amountofpoints > 400000 && amountofpoints < 500000):             {                 price = 150;                 break;             }         case (amountofpoints > 500000 && amountofpoints < 600000):             {                 price = 150;                 break;             }         case (amountofpoints > 600000 && amountofpoints < 700000):             {                 price = 160;                 break;             }         case (amountofpoints > 700000 && amountofpoints < 800000):             {                 price = 185;                 break;             }         case (amountofpoints > 800000 && amountofpoints < 900000):             {                 price = 210;                 break;             }         case (amountofpoints > 900000 && amountofpoints < 1000000):             {                 price = 235;                 break;             }         case (amountofpoints <= 1000000):             {                 tweetsprice = 200;                 break;             }         default:             price = 0;             break;     } } 

any how can calculate if points > 1,100,000? should increment $20 each 100,000.

usually, works this:

function calcprice(value) {   if (value <= 500000) {     return 30 * math.ceil(value / 100000);   } else if (value <= 1000000) {     return 150 + 25 * math.ceil((value - 500000) / 100000);   } else {     return 275 + 20 * math.ceil((value - 1000000) / 100000);   } } 

but going letter of post:

function calcprice(value) {   if (value <= 500000) {     return 30 * math.ceil(value / 100000);   } else if (value <= 1000000) {     return 25 * math.ceil(value / 100000);   } else {     return 20 * math.ceil(value / 100000);   } } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -