Can ZP calculate percentages?

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Реакции
26
Баллы
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?
 
Код:
Развернуть Свернуть Копировать
double price= 200;
double percent =13.5;
double total = price+price*percent/100;
return total;
 
  • Спасибо
Реакции: shabbysquire
Код:
Развернуть Свернуть Копировать
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-)
 
Последнее редактирование:
  • Спасибо
Реакции: LightWood
Sorry, I don't mean to add the currency; just add 5 to the percent total.
 
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.
 
  • Спасибо
Реакции: shabbysquire
..
C#:
Развернуть Свернуть Копировать
int price = int.Parse(project.Variables["price"].Value);
return price*13.5/100+price;
 
  • Спасибо
Реакции: shabbysquire
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 =
 
I suppose it should be like this:
Код:
Развернуть Свернуть Копировать
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;
 
Последнее редактирование:
..
C#:
Развернуть Свернуть Копировать
int price= 200;
double total = price+price*13.5/100+5;
return total+0.1*total+0.034*total+0.2;
 
Ok, I messed around with it (I don't know c#!), but I came up with this:

Код:
Развернуть Свернуть Копировать
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.
 
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...
 
Ok, so you mention possible double paypal, so I've added to ebay as a total of: 13.4:

Код:
Развернуть Свернуть Копировать
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.
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)