founding a percentage - Resolved !!!

founding a percentage - Resolved !!!

Postby Silvio.Falconi » Tue Jan 29, 2019 3:55 pm

I have a nprice to calculate


unit cost 15 euros
the discount is calculated on the basis of - (ncost * percentage/ 100)
But I not Know the right percentage to insert
I tried with 10,12 and 13 but it not run ok

sample :
if it costs 30 euros the percentage discount makes me 28.05 while it should be 25 for 2 products ( perhaps -5)
if it costs 45 euros the percentage discount makes me 41.10 while it must be 40 for 3 products ( perhaps -5)
if it costs 60 euros the percentage discount makes me 54.15 while it should be 50 for 4 products ( perhaps -10)
if it costs 75 euros the percentage discount makes me 67.20 while it should do 60 for 5 products ( perhaps - 15)


How I can calculate the exactly percentage ?

any solution ?
Last edited by Silvio.Falconi on Wed Jan 30, 2019 8:15 pm, edited 1 time in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: founding a percentage

Postby EBM » Tue Jan 29, 2019 4:07 pm

Hola Silvio:

Creo que se soluciona asi:

Descuento = ( 1 - ( Precio Neto / Costo ) ) * 100 --> Porcentaje de descuento aplicado

Espero te sirva

Saludos!

Eduardo Borondón Muñiz
EBM
 
Posts: 147
Joined: Tue Oct 11, 2005 8:22 pm
Location: Guadalajara, Jal Mexico

Re: founding a percentage

Postby karinha » Tue Jan 29, 2019 5:29 pm

See if it helps. I did not quite understand your writing.

Code: Select all  Expand view  RUN

#include "FiveWin.ch"

static oWnd

//----------------------------------------------------------------//

function Main()

   LOCAL nPrice    := 0.00
   LOCAL nCost     := 0.00
   LOCAL nPercent  := 0.00
   LOCAL nDiscount := 0.00
   LOCAL nTotal    := 0.00


   nPrice    := 15.00
   nCost     := 10.00
   nPercent  := 10.00


   nDiscount := ( nCost ) * ( nPercent ) / 100

   ? nDiscount

   nDiscount := ( 1 - ( nPrice ) / ( nCost ) ) * 100

   ? nDiscount

   nDiscount := ( 1 - ( nPrice ) / ( nCost ) * ( nPercent ) ) / 100

   ? nDiscount

return nil
 


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7835
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: founding a percentage

Postby Silvio.Falconi » Wed Jan 30, 2019 8:15 am

Not run ok
Please

Local nCostoUnitario:= 15
Local nSconto:= 0
Local adata:={}
Local lIncremental: =.t.
Local nConsto:= 0
Local nPercentuale:= 12.50 //test


For n= 1 to 30
nCosto:= nCostounitario*n
nTotale:= nCosto-nSconto
aadd(adata,{n,;
nCosto ,;
nSconto ,;
nTotale })

If lIncremental
nsconto:= (ncosto*nPercentuale/100)
Endif
next

xbrowser aData TITLE " Price List June"

on oldest application I have this ..but I not found how I made (I lose the function)

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: founding a percentage

Postby ADutheil » Wed Jan 30, 2019 11:18 am

You discount isn't based on fixed %. Look:

1 -> 13/15 = 0,866%
2 -> 25/30 = 0,833%
3 -> 40/45 = 0,888%
4 -> 50/60 = 0,833%
5 -> 60/75 = 0,800%

if you want to calculate the final amount based on the quantity of products according to the picture you sent, you should do something like this:

FUNCTION FinalCost( nQtdUnits, nUnitValue )
LOCAL nFinalCost

IF nQtdUnits = 1
nFinalCost := nUnitValue - 2
ELSEIF nQtdUnits = 2
nFinalCost := ( nUnitValue * nQtdUnits ) - 5
ELSE
nFinalCost := ( nUnitValue * nQtdUnits ) - ( ( nQtdUnits - 2 ) * 5 )
ENDIF

RETURN nFinalCost
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: founding a percentage

Postby Silvio.Falconi » Wed Jan 30, 2019 3:46 pm

thanks run ok

I change with
Code: Select all  Expand view  RUN
FUNCTION FinalCost( nQtdUnits, nUnitValue,nPercentual )
   LOCAL nFinalCost
    Local nMidPercentual :=  Int(nPercentual/2)

     IF nQtdUnits = 1
       nFinalCost := nUnitValue - nMidPercentual
     ELSEIF nQtdUnits = 2
        nFinalCost := ( nUnitValue * nQtdUnits ) - nPercentuale
     ELSE
       nFinalCost := ( nUnitValue * nQtdUnits ) - ( ( nQtdUnits - nMidPercentual ) * nPercentuale )
    ENDIF

RETURN nFinalCost


and thenI can insert also a percentual on get ( from final user)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 37 guests