founding a percentage - Resolved !!!

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

founding a percentage - Resolved !!!

Post 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 ?
Last edited by Silvio.Falconi on Wed Jan 30, 2019 8:15 pm, edited 1 time in total.
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
EBM
Posts: 123
Joined: Tue Oct 11, 2005 8:22 pm
Location: Guadalajara, Jal Mexico

Re: founding a percentage

Post 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
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: founding a percentage

Post by karinha »

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

Code: Select all

#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
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: founding a percentage

Post 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
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
ADutheil
Posts: 352
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: founding a percentage

Post 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
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: founding a percentage

Post by Silvio.Falconi »

thanks run ok

I change with

Code: Select all

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)
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply