Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Text conversion to big number
Message
De
27/09/2020 15:04:01
 
 
À
26/09/2020 12:09:31
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01676260
Message ID:
01676280
Vues:
53
I created a BigNums DLL for this express purpose (doing math in larger forms). It will do it. It presents as a logical spreadsheet, and you can see from the example code how it works. When you specify the precision, make sure you pass in a string with at least that many SPACE(n) characters defined because it will populate into that string.

See "Arbitrary Precision Floating Point" library, "abritrary precision" means it can grow as large as you need, and is not just 32-bit or 64-bit representation.
https://www.levelextreme.com/Home/ViewPage?Activator=1021&ID=1674808

This is the minimal set of functions you'd be interested in:
* Use one time in your initialization code:
DECLARE INTEGER bgn_Initialize IN bignums.dll INTEGER nRows, INTEGER nCols
DECLARE INTEGER bgn_SetPrecision IN bignums.dll INTEGER nDigits
DECLARE INTEGER bgn_SetValue IN bignums.dll STRING cCell, STRING cValue
DECLARE INTEGER bgn_GetValue IN bignums.dll STRING cCell, INTEGER nWidth, INTEGER nDecimals, STRING@ output
DECLARE INTEGER bgn_SetFormula IN bignums.dll STRING cCell, STRING cFormula
bgn_Initialize(100, 50)
bgn_SetPrecision(32)

* Use as-needed to set your data:
bgn_SetValue("A1", "104020109010404010101")

* Use as-needed to retrieve your data:
lcResult = SPACE(32)
bgn_GetValue("A1", 32, 0, @lcResult)
* Answer is in ALLTRIM(lcResult)

* You can do any math you want to with it:
bgn_SetValue("B1", "5")
bgn_SetFormula("B2", "A1+B1")

* Each time you read the cell with a formula, it re-computes and you'll get the new value.
* So you can populate new values into B1, and it will re-compute each time.
lcResult = SPACE(32)
bgn_GetValue("B2", 32, 0, @lcResult)
* Answer is in ALLTRIM(lcResult)
Also, you can also use CHRTRAN(string, ".", SPACE(0)) to get rid of the periods in a number and just have the digits.
lcSource = "1.2.11.3"
lcConverted = CHRTRAN(lcSource, ".", SPACE(0))
? lcConverted
>Hi,
>
>I need to convert a text. e.g 1.2.11.3 to a number like 1021103 for which I constructed a method:
>
>
>*!* PROCEDURE conversion
>LPARAMETERS lcNumberIn
>
>Local ;
>	lcNewpar As String, ;
>	lcNumberIn As String, ;
>	lnI As Number, ;
>	lnParenteel As Number
>
>
>*!*	? lcNumberIn
>m.lcNewpar = ''
>
>For m.lnI = 1 To Len(Alltrim(m.lcNumberIn ))
>	Do Case
>		Case !Isdigit(Substr(m.lcNumberIn ,m.lnI,1))
>			m.lcNewpar = m.lcNewpar +Substr(m.lcNumberIn ,m.lnI,1)
>		Case Isdigit(Substr(m.lcNumberIn ,m.lnI,1))
>			m.lcNewpar = m.lcNewpar + Iif(Isdigit(Substr(m.lcNumberIn ,m.lnI,1)), Padl(Substr(m.lcNumberIn ,m.lnI,1),2,'0'), Substr(lcParenteel  ,m.lnI,1))
>
>	Endcase
>Endfor 
>m.lcNewpar = Strtran(m.lcNewpar ,'010','1')
>m.lcNewpar = Strtran(m.lcNewpar ,'.','')
>m.lcNewpar = ALLTRIM(Substr(m.lcNewpar ,2))
>RETURN val(m.lcNewpar)
>
>
>Now I come to a text 1.4.2.1.9.1.4.4.1.1.1 which would be 104020109010404010101 however this are to much digits vor VFP to handle thus my method gives 1040201090104+E
>
>How to solve for such big numbers?
>Stay healty,
>Koen
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform