Code HELP | Conditional/Variable IF Codes

By: Tina Marker | Asked: 06/23/2023
ForumsCategory: Code HelpCode HELP | Conditional/Variable IF Codes
Tina Marker asked 1 year ago

 Here is my coding question. I wrote the formula below to calculate up to $150,000:

 ([210] < 150000) ? (.00575 * [210]) :  ([210] > 150000) ? (.00450 * [210]) :  ([210] > 250000) ? (.00350 * [210]) :  ([210] > 500000) ? (.00275 * [210]) :  ([210] > 10000000) ? (.00225 * [210]) : (175)

After the above purchase amount, the required calculations become prorated and more complex. How to write the formula in Formidable to manage all of these variables for purchases above $150k?

Current Premium costs per $1000.00

Up to $150,000 - $5.75 per 1M 

$150,000 to $250,000 add $4.50 per 1M

$250,000 to $500,000 add $3.50 per 1M

$500,000 to $10,000,000 add $2.75 per 1M

Over $10,000,000 add $2.25 per 1M

Minimum premium $175

 

__________

Excel formula example with different variables as an example to show the process used:

Let's say the purchase price is $425,000 (note: percentages in examples are different than ones needed)

The first $150,000 x 6.61 = 991.50

The next 100,000 x 5.18 = 518.00

Then 175,000 x 4.03 = 705.25

$425,000 = 2214.75 total premium

 if(a1<=150000,a1*0.00661,if(a1<=250000,(a1-150000)*0.00518+991.5,if(a1<=500000,(a1-250000)*0.00403+1509.5,if(a1<=10000000,(a1-500000)*0.00316+2517,if(a1>10000000,(a1-10000000)*0.00259+32537)

 

1 Answers
Rob LeVineRob LeVine answered 1 year ago
I'm not going to jump on this grenade, so I'll just suggest the way I'd handle a complex equation like that. I'd create a custom shortcode, pass in the value as a parameter and do all the math in a clean, concise, and easy-to-read block of PHP code, rather than in a single line. https://developer.wordpress.org/plugins/shortcodes/shortcodes-with-parameters/

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right