prices breakdown
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
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
![Image](https://i.postimg.cc/FsdHtDgW/mm.png)
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
![Image](https://i.postimg.cc/FsdHtDgW/mm.png)
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
- Code: Select all Expand view
- #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 aRet