• Resolved alexvds

    (@alexvds)


    Dear Sir,

    I have a problem wrtining a short code for my site. I have tried several solutions (witch or, and else) witch i have found on this forum, unfortunally nothing is working.

    I want to make a code witch, depending on the users input, calculate a som, its for calculating the debt cost in Holland. Can u please help me with this: I have te following input:

    (function(){

    if(fieldname3 < 266,6666666666667) return fieldname7;

    if(fieldname3 > 266,6666666666667) return fieldname3*0.15;

    if(fieldname3 > 2500) return fieldname3*0.10+375;

    if(fieldname3 > 5000) return fieldname3*0.05+625;

    if(fieldname3 > 10000) return fieldname3*0.01+875;

    if(fieldname3 > 200000) return fieldname3*0.005+2775;

    (and the last may never been higher than € 6.775,00)

    })();

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    There are multiple issues in your equation:

    – First, in javascript, the decimal symbol is the dot (.), and not the comma (,). So, the correct representation would be: 266.6666666666667, and not: 266,6666666666667

    – Second, if the first condition is:

    fieldname3 < 266.6666666666667 with a return statement,

    and the second one is:

    fieldname3 > 266.6666666666667 with a return statement,

    Both conditions cover all the spectrum so, the rest of the equations won’t be reached.

    So, the equation should be edited as follows:

    (function () {
    
    	if (fieldname3 < 266.66)
    		return fieldname7;
    	else if (fieldname3 <= 2500 )
    		return fieldname3 * 0.15;
    	else if (fieldname3 <= 5000)
    		return fieldname3 * 0.10 + 375;
    	else if (fieldname3 <= 10000)
    		return fieldname3 * 0.05 + 625;
    	else if (fieldname3 <= 200000)
    		return fieldname3 * 0.01 + 875;
    	
    	return MIN(fieldname3 * 0.005 + 2775, 6775);
    })()

    If you need additional help with your equation, I can offer you a custom coding service, from my personal website:

    http://cff.dwbooster.com/customization

    Best regards.

    Thread Starter alexvds

    (@alexvds)

    Thanks! This is great, its finally working! You’re really good!

    • This reply was modified 8 years, 7 months ago by alexvds.
    • This reply was modified 8 years, 7 months ago by alexvds.
    Thread Starter alexvds

    (@alexvds)

    I have one last question about this. Ofcourse it shows now always fieldname7 because there is no input (so the amount is in the beginning always beneath € 266.66). Is there a possibility to clear the fieldname in te case there is no input yet?

    Plugin Author codepeople

    (@codepeople)

    Hello,

    You will need something similar to:

    (function () {
       if(fieldname3){
    	if (fieldname3 < 266.66)
    		return fieldname7;
    	else if (fieldname3 <= 2500 )
    		return fieldname3 * 0.15;
    	else if (fieldname3 <= 5000)
    		return fieldname3 * 0.10 + 375;
    	else if (fieldname3 <= 10000)
    		return fieldname3 * 0.05 + 625;
    	else if (fieldname3 <= 200000)
    		return fieldname3 * 0.01 + 875;
    	
    	return MIN(fieldname3 * 0.005 + 2775, 6775);
       }
       return ''; 
    })()
    Thread Starter alexvds

    (@alexvds)

    Great, Awsome!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘if-or-else-and formule’ is closed to new replies.