Page 1 of 1

founding a percentage - Resolved !!!

PostPosted: Tue Jan 29, 2019 3:55 pm
by Silvio.Falconi
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 ?

Re: founding a percentage

PostPosted: Tue Jan 29, 2019 4:07 pm
by EBM
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

Re: founding a percentage

PostPosted: Tue Jan 29, 2019 5:29 pm
by karinha
See if it helps. I did not quite understand your writing.

Code: Select all  Expand view

#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
 



Re: founding a percentage

PostPosted: Wed Jan 30, 2019 8:15 am
by Silvio.Falconi
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

Re: founding a percentage

PostPosted: Wed Jan 30, 2019 11:18 am
by ADutheil
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

Re: founding a percentage

PostPosted: Wed Jan 30, 2019 3:46 pm
by Silvio.Falconi
thanks run ok

I change with
Code: Select all  Expand view
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)