I have to convert a total price into columns and positions relative to this system, i.e. the total price must be broken down into parts according to the scheme
aImports:={200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05}
for a sample :
total price 1.20 it return me
col - Row
9 --------1
11 -------1
the total max is 391.85 is the sum of all columns
I made a test but there is an error because then the 4 position it jump to 9 and I not understood why

the second column of xbrowse it the row of scheme and the first are the columns
as you can see it cal 1,2,3,4 then make error
my test
aImports:={200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05}
for a sample :
total price 1.20 it return me
col - Row
9 --------1
11 -------1
the total max is 391.85 is the sum of all columns
I made a test but there is an error because then the 4 position it jump to 9 and I not understood why

the second column of xbrowse it the row of scheme and the first are the columns
as you can see it cal 1,2,3,4 then make error
my test
#include "Fivewin.ch"
function test()
local abolletta := {391.85,0,0,0,0,0}
local aImports := Restore_Prices(abolletta)
XBROWSER aImports
return nil
//---------------------------------------------------------------------//
Function Restore_Prices(aTotali)
local nRiga
local nColonna,nNumero
local nI
local nTotale
local aData:= {}
local aDataX:= {}
For ncolonna= 1 to 6
nTotale:= aTotali[ncolonna]
aData:= {}
//righe
aData:= BinCalc(nTotale)
For k= 1 to Len(adata)
nriga:=adata[k]
AaDd(aDataX,{nriga,nColonna} )
Next
Next
return aDataX
Function BinCalc(nValue)
LOCAL aImports:={200,100,50,20,10,5,3,2,1,0.50,0.20,0.10,0.05}
LOCAL nPosition := 0
LOCAL nRest := nValue
LOCAL aRet := {}
DO WHILE .T.
nPosition := ASCAN(aImports,{|e| e <= nRest})
IF nPosition > 0
AADD(aRet,nPosition)
nRest -= aImports[nPosition]
ELSE
EXIT
ENDIF
ENDDO
RETURN aRetSince 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
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







