HTML5 Data Bindings Formatter Support Product Page

Answered

How do I calculate a % value out of two database fields?

Asked 23 Mar 2015 10:56:50
1
has this question
23 Mar 2015 10:56:50 Andre Bender posted:
How do I realize the follwoing classic php with your extension?

<?php		 $x = $row_webartikel['Preis'];
			 $y =$row_webartikel['PreisSpezial'];
			 $Prozent = ($x-$y)/$x*100;
			 echo round($Prozent,0);?>


Thanks for any help

Replies

Replied 23 Mar 2015 11:25:37
23 Mar 2015 11:25:37 Teodor Kuduschiev replied:
Hi Andre,
You can do this like:

{{((Preis-PreisSpezial)/Preis*100).round( )}}

Replied 23 Mar 2015 11:54:35
23 Mar 2015 11:54:35 Andre Bender replied:
Hi Teodor

Thanks. It looks like that this part:

((Preis-PreisSpezial)/Preis*100)

Isn't working. It's not returning a vlaue.
Replied 23 Mar 2015 12:00:49
23 Mar 2015 12:00:49 Teodor Kuduschiev replied:
I jut tested this locally and all appears to be working fine. Can you provide a link to your page?
Replied 23 Mar 2015 12:51:45
23 Mar 2015 12:51:45 Andre Bender replied:
I'll send you the link to
Replied 23 Mar 2015 14:22:47
23 Mar 2015 14:22:47 Andre Bender replied:
The division sign "/" seems to be incorrect... How is the correct way to use it? Any API documentation for your extension??
Replied 23 Mar 2015 14:58:05
23 Mar 2015 14:58:05 Teodor Kuduschiev replied:
The division should be done with "/", most probably your data should be formatted as number. Please try:

{{((Preis-PreisSpezial).toNumber()/Preis.toNumber()*100).round( )}}

Replied 23 Mar 2015 15:10:52
23 Mar 2015 15:10:52 Andre Bender replied:
Thanks Teodor. But that didn't work either.

"Preis" and "PreisSpezial" are saved as double values in the database.
Replied 23 Mar 2015 15:59:17
23 Mar 2015 15:59:17 Andre Bender replied:
This is NOT working:

{{((50-10)/50*100).round( )}}

This is NOT working:

{{((40)/50*100).round( )}}

This is working:

{{(40/50*100).round( )}}

Doesn't seem to be a number formatting, but a ( ) problem.

Reply to this topic