Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calculating very large numbers
Message
De
09/09/2009 05:03:39
 
 
À
09/09/2009 04:19:15
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01423218
Message ID:
01423225
Vues:
93
This message has been marked as a message which has helped to the initial question of the thread.
>Dear All
>
>Is there any way to make precise calculation without number being rounded
>
>? 22919090710007290*100/97
>
>Returns rounded number. I need actual remainder.
>Mod(22919090710007290*100,97) returns 0
>
>What are the options.
>
>TIA
>Sergio

Try this. It's similar to Boris' solution - also from my Iban

Since the precision of double is about 15.95 digits - 15 to be safe - it calculates how many digits (for/next/step) it can take per calculation

In the case of mod 97 that would be steps of 13
*--------------------------------------------------------------------------
function Do_it()
	
	?Mod_String('2291909071000729000', 97)
	
endfunc
*--------------------------------------------------------------------------
function Mod_String(s, Divisor)

	local StepSize, StepMultiplier, i, n
	
	StepSize = (15 - ceiling(log10(m.Divisor)))
	StepMultiplier = int(10 ^ m.StepSize)
	
	n = 0
	
	for i = 1 to len(m.s) step m.StepSize 
		n = mod(int(m.n * m.StepMultiplier) + int(val(substr(m.s, m.i, m.StepSize))), m.Divisor)
	endfor
	
	return m.n
endfunc
*--------------------------------------------------------------------------
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform