Skip Navigation

[Resolved] Another question about calculations

This support ticket is created 9 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 4 replies, has 2 voices.

Last updated by dbarber 9 years, 3 months ago.

Assigned support staff: Bigul.


I need to do a slightly more complex calculation than discussed over here

Basically, I need to do a calculation like this:

(A - B) / B

And I need it to output as a percentage limited to 2 decimal points.

I've tried to work it out on my own, but haven't had any luck so far.

Any help would be greatly appreciated.





Dear Dbarber,

Easy solution will be you can write a custom function for this purpose. Then pass A & B as arguments. Then calculate (A – B) / B inside the custom function.

Please try it and let me know your feedback.

If you are still facing the problem, please share the function and short code you are using. Also describe little more about your custom fields.

With Regards



Hi Bigul

I still need a solution for this, but I'm not sure how to do what you've advised so I can't share a function or shortcode.

Here's more detail on the fields I need to evaluate:

[types field="detached-sales-current" raw="true" id=""][/types] minus
[types field="detached-active-listings-current" raw="true" id=""][/types] divided by [types [field="detached-active-listings-current" raw="true" id=""][/types]

And I need it to output as a percentage, limited to 2 decimal points, and, if the result is less than 0.00, I need the output to be colored red.

Thanks for your assistance with this.





Dear Dawson,

Hope you are trying to achieve the following.

[types field="detached-sales-current" raw="true" id=""][/types] = A

[types field="detached-active-listings-current" raw="true" id=""][/types] = B

The formula is (A - B) / B

You can write a custom function for this purpose like the following.

add_shortcode('wpv-formula-calculate', 'formula_calculate');
function formula_calculate($atts) {
	$result = wpv_condition($atts);
	if($result < 0){
		return '<font color="red">'.number_format($result,2)."%</font>";
		return number_format($result,2)."%";

Then call it inside views like the following.

[wpv-formula-calculate evaluate='([types field="detached-sales-current"][/types] - [types field="detached-active-listings-current"][/types])/ [types field="detached-active-listings-current"][/types]']

Please try it and let me know your feedback.

With Regards



Hi Bigul

I realized that I haven't done a good job asking for help because I have a few support threads open that I realized cannot be resolved independent of one another so I decided to start a fresh thread that combines all them.

Here's the new "all in one" thread:

I really appreciate your excellent support and apologize for having taken up your time. I should have thought this through more fully before asking for assistance.