0

Is there a simple way to do this calculation on a page without using PHP on output? I have a member_field with a value and a channel_field with a value and want to output

{member_field} * {channel_field} = 

1 Answer 1

5

There is no direct way. I suggest you to install this module

Edit

If incase you have values to pass with comma separated (i.e., 5,00,000.05), You need to edit pi.math.php file to add this code on line number 54.

// remove commas
$formula = str_replace("," , "" , $formula);
5
  • 1
    Thank you. Unfortunately this plugin can not handle values with a comma. The dec_point parameter does not react to ','. Other than that, useful answer. Commented Jan 18, 2018 at 7:43
  • Not to worry about that. Just edit the plugin pi.math.php and add this code on line number 54. $formula = str_replace("," , "" , $formula); Commented Jan 18, 2018 at 12:14
  • Have not tried that. I fear a missunderstanding. It's not the comma as a thousend separator, it's the comma as the decimal separator like in a currency like EUR 20,50. If we have EUR 20.50 the the plugin calculates. But 20,50 output is needed in Germany. Commented Jan 18, 2018 at 14:55
  • If you need to covert all , to use as decimal. You can change str_replace accordingly. Something like $formula = str_replace("," , "." , $formula); Commented Jan 18, 2018 at 15:07
  • 1
    Have inserted that line of code - one line above this: @eval("\$result = $formula;");. 2 x EUR 2,00 = EUR 400.00 is the result when Cartthrob has the decimal separator to comma. Only if it is the point then I get the result of the formula right. Commented Jan 18, 2018 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.