how to add a simple php calculation in email

Fl FloB 25 Mar, 2013
Hello!
It seems to me that there is an error in your code:
<?php $oantal=&form->data['oantal'] echo 7,50*$oantal;?>

should be
<?php $oantal=$form->data['oantal'] echo 7,50*$oantal;?>


Then, are you sure that $form->data['oantal'] is a number or a numeric value, because if it is a text, this couldn't work.

Flo
Li Liesbeth 25 Mar, 2013
Hi Flob,

Thanks for your quick reply,
I get a blank email with the adjusted code
(yes, The field "oantal" is a number.)

Any other suggestions would be welcome.

Kind Regards,
Liesbeth
Fl FloB 25 Mar, 2013
Hi!
Try adding a ";" before the echo and change the "," by a ".":
<?php $oantal=$form->data['oantal']; echo 7.50*$oantal;?>


Flo
Li Liesbeth 25 Mar, 2013
Thank you very much, it works just fine!

Do you have a hint how I can change the "." into a "," so the output will be (for example) 30,00 euro instead of 30.00 euro?
Fl FloB 25 Mar, 2013
The following code permits to set the number of decimals, the decimal separator and the thousand separator : string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

You can use it like this:
<?php $oantal=$form->data['oantal']; echo number_format(7.50*$oantal, 2, ',', ' ');?>

to have 2 decimals after a "," and thousands separated by a " ".

If you start using php, I have found this web site no long ago (newbe myself).

Good luck
Flo
This topic is locked and no more replies can be posted.