Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculating very large numbers
Message
From
09/09/2009 05:03:39
 
 
To
09/09/2009 04:19:15
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01423218
Message ID:
01423225
Views:
92
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
Previous
Reply
Map
View

Click here to load this message in the networking platform