The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.
Hi,
This plugin provides support for doing simple mathematical operations in templates.
There is already the plugin Mathematical Operations by Yuriy Salimovskiy which has the same purpose. My plugin is more powerful since it
1) allows more mathematical operations;
2) allows to input more than two numbers;
3) allows to control order of mathematical operations by using round brackets.
PARAMETERS
1) calculate - Required. Allows you to input a string consisting of numbers, symbols of mathematical operations, symbols of mathematical functions and round brackets, e.g calculate = “(10 + 5) / 3”. You can use such symbols of mathematical operations as: + (addition), - (subtraction), * (multiplication), / (division), % (division remainder), ++ (increment), – (decrement); also you can use symbols of mathematical functions, e.g. round(), floor(), ceil().
2) invalid_input - Optional. Accepts two values: “alert” and “silence”. Default value is “silence”. If the value is “alert”, then in cases when the plugin has some problem with parameters, PHP alert is being shown; if the value is “silence”, then in cases when the plugin has some problem with parameters, it finishes its work without any alert being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.
EXAMPLE OF USAGE
The code
{exp:simple_math calculate="(11 + 4) / 3"}
will output “5”.
The code
{exp:simple_math calculate="ceil((10 + 6) / 3)"}
will output “6”.
There is also Math Plus plugin which differs from Simple Math only in one feature: it is required to use a tag pair instead of single tag. Tag pair allows for better control of the parse order.
Would it be possible to use this plugin for a price calculator…
Otherwise I assume PHP could be used.
Any insights or recommendations?
Hi Mark,
It seems that Simple Math plugin can be useful for your purpose.
You only need to find a way how to input Quantity - maybe using PHP Session Variables? (There is Session Variables plugin, but it would need to be rewritten in order to use together with Simple Math).
The code would be as follows:
{exp:weblog:entries weblog="my_weblog" url_title="my_url_title" parse="inward"}
{exp:simple_math calculate="(<?php echo $quantity ?> * {unit_price}) + {setup_fee}"}
{/exp:weblog:entries}
I am trying to use the Simple Math plugin with a variable using the following code.
Tax = {exp:simple_math calculate="{total} * .07”}
if {total} is outside of the simple_math expression it works fine and produces a value but when added to simple math expression, I get this error…
Parse error: syntax error, unexpected ‘{’ in /home/sweettee/public_html/EE/files/plugins/pi.simple_math.php(65) : eval()’d code on line 1
Can anyone help me on this as I really need to get this to work.
Thanks, Candi
Hi Candi,
If you don’t mind my popping in on this one I’m not too sure what it is that you’re trying to do here but I would ask that you don’t share the Shopping Cart Plugin code with anyone as it is a paid product and as such I don’t really want it being sent out to anyone that hasn’t purchased it or the code being shown on the forums here. As the plugin is a paid plugin a lot of people won’t even know what it is or what it does so you may or may not get the answers you are after here.
I don’t know if you’ve already contacted me about this or not but if not then perhaps you could explain to me what you are trying to do and I can see if I can help maybe. The Shopping Cart Plugin does already contain totals and all those variables so I’m not too sure from looking at the code above exactly what it is that you are trying to do but if you can explain to me then perhaps I can help. Might also be best to either PM me or email me as I don’t want to take away from this thread if we can help it.
Thanks for your understanding on this.
Best wishes,
Mark
I’m trying to use this plugin in conjunction with SL Currency Converter, but get an error when trying to do this:
{exp:simple_math calculate="ceil( {exp:sl_currencyconverter:convert amount="{price_rand}" base="ZAR" target="GBP"} ) + {related_entries id="price_level"}{markup}{/related_entries}"}
It errors on the second {exp:} tag (substituting a static value works OK) - is this an issue with the plugin, or can I not embed {exp:} tags?
Thanks,
Have you tried parse=”inward”?
Yeah, doesn’t want to work (on either {exp:}, just to be certain). =/
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.