Can ZP calculate percentages?

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Would like to know how to get ZP to calculate percentages. i.e. I need to take a price, then add, say, 13.5% to the total.

Is this possible?
 

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,862
Reaction score
1,193
Points
113
Any math is possible mate.

Price = 100 Eur
Add = 13%

Final = 100 x 0.13 = 13 Eur = 100 + 13 = 113 Eur

Answer final price with 13% added will be 113 Eur in this case

Cheers
 

VladZen

Administrator
Staff member
Joined
Nov 5, 2014
Messages
22,588
Reaction score
5,952
Points
113
Code:
double price= 200;
double percent =13.5;
double total = price+price*percent/100;
return total;
 
  • Thank you
Reactions: shabbysquire

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Code:
double price= 200;
double percent =13.5;
double total = price+price*percent/100;
return total;
Thanks man, that works a treat!

Just one more question. Once I've use the c# to calculate the %, how do I add, say, £5 to the sum (which action)? I'm not familiar with maths in ZP! 8-)
 
Last edited:
  • Thank you
Reactions: LightWood

VladZen

Administrator
Staff member
Joined
Nov 5, 2014
Messages
22,588
Reaction score
5,952
Points
113

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Sorry, I don't mean to add the currency; just add 5 to the percent total.
 

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Vlad; that solution that you gave me is causing major bugs in my template. When I delete the c#, everything works as normal.

I'm gonna stick this into bugs section.
 

VladZen

Administrator
Staff member
Joined
Nov 5, 2014
Messages
22,588
Reaction score
5,952
Points
113
Vlad; that solution that you gave me is causing major bugs in my template. When I delete the c#, everything works as normal.
I'm gonna stick this into bugs section.
There is nothing that can cause bugs... Please give the details. What errors you get.
 

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
I've added it here.
 

VladZen

Administrator
Staff member
Joined
Nov 5, 2014
Messages
22,588
Reaction score
5,952
Points
113
Sorry, I don't mean to add the currency; just add 5 to the percent total.
Code:
double price= 200;
double percent =13.5;
double total = price+price*percent/100+5;
return total;
 
  • Thank you
Reactions: shabbysquire

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Many thanks, has done the job!
 

ssXXXss

Client
Joined
Dec 23, 2014
Messages
7,375
Reaction score
2,042
Points
113
..
C#:
int price = int.Parse(project.Variables["price"].Value);
return price*13.5/100+price;
 
  • Thank you
Reactions: shabbysquire

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Ok, just to add additional elements to the above:

Item price = 15.00;
My profit margin = 5.00;

So total of above: 20.00

Then to add in the following:
ebay fees = 10%
Paypal fees = 3.4% + 0.20;
Total =
 

VladZen

Administrator
Staff member
Joined
Nov 5, 2014
Messages
22,588
Reaction score
5,952
Points
113
I suppose it should be like this:
Code:
double price= 200;
double percent =13.5;
double total = price+price*percent/100+5; // calculating price+percent+profit margin
double extratotal = total+0.1*total+0.034*total+0.2; // calculating total price+ebay fee+paypal fee
return extratotal;
 
Last edited:

ssXXXss

Client
Joined
Dec 23, 2014
Messages
7,375
Reaction score
2,042
Points
113
..
C#:
int price= 200;
double total = price+price*13.5/100+5;
return total+0.1*total+0.034*total+0.2;
 

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Ok, I messed around with it (I don't know c#!), but I came up with this:

Code:
double price= double.Parse(project.Variables["amazon_price"].Value); //Amazon item price
double profit = 5.0;  // My profit margin
double ebay = 10.00;  // ebay's final  selling fees (%)
double paypal = 3.4+0.20; // Paypal fee of 3.4% and 0.20
double total = price+price*ebay*paypal/100+profit; // calculating price+percent+profit margin
return total;
The amazon product price is: £15.39 with my £5 profit.

Then add ebay fee at 10%, and Paypal fee at: 3.4 + 0.20. The total is supposed to be: £17.63, but my alteration to the code job shows: £18.90.

Can anyone see the mistake in the code?

Btw, I need to keep everything in the above format, as sometimes ebay/paypal fees change (so I can simply change it quickly!)
Thanks.
 

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,862
Reaction score
1,193
Points
113
Most probably problem is there double paypal = 3.4+0.20; // Paypal fee of 3.4% and 0.20

As I see there is percents added to cents.
And another thing is you have to know what % counts first, because if you add 10% first and then 3,4% after that or 3,4% first and 10% after that then result will be different also...
 

shabbysquire

Client
Joined
Nov 25, 2012
Messages
544
Reaction score
26
Points
28
Ok, so you mention possible double paypal, so I've added to ebay as a total of: 13.4:

Code:
double price= double.Parse(project.Variables["amazon_price"].Value); //Amazon item price
double profit = 5.0;  // My profit margin
double fees = 13.4;  // ebay's 10%, and Paypal's 3.4% (the 20p part of Paypal is in total)
double total = price+price*fees/100+profit+0.2; // calculating price+percent+profit margin, and 20p part for the Paypal fee
return total;
But now the calculation is off; supposed to be £17.63, but this displays: £16.98.
 

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,862
Reaction score
1,193
Points
113

Users Who Are Viewing This Thread (Total: 2, Members: 0, Guests: 2)