FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour founding a percentage - Resolved !!!
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
founding a percentage - Resolved !!!
Posted: Tue Jan 29, 2019 03: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 ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 147
Joined: Tue Oct 11, 2005 08:22 PM
Re: founding a percentage
Posted: Tue Jan 29, 2019 04: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

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: founding a percentage
Posted: Tue Jan 29, 2019 05:29 PM
See if it helps. I did not quite understand your writing.

Code (fw): Select all Collapse
#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
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: founding a percentage
Posted: Wed Jan 30, 2019 08: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)

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: founding a percentage
Posted: 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

Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: founding a percentage
Posted: Wed Jan 30, 2019 03:46 PM
thanks run ok

I change with
Code (fw): Select all Collapse
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 March-April 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

Continue the discussion