Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Decimal precision
Message
From
23/05/2012 11:27:23
 
 
To
23/05/2012 11:13:11
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01544101
Message ID:
01544152
Views:
27
>BTW, in that formula, I entered by mistake the amount (500.00$) instead of the tax amount (74.88$) and it ended up in an infinite loop. Do you know what would need to be adjusted in the formula to avoid an infinite loop in case a bad tax amount would be provided?

I'ts not a loop, it just ends without finding a solution because a total tax of $500.00 does not exist

What happens is that fedTax + provTax is 499.99 at one moment and the next iteration it is 500.01

So I have added an extra if: fedTax + provTax > Totaltax, then adjust provTax to be totalTax - fedtax so that the sum of both of them is 500.00
	totalTax  = 500.00
	f = .05
	p = .095
	
	base =  round(totalTax  / (f*p + f + p), 2)

	
	for i = base  - .50 to base + 0.50 step .01
		fedTax = round(i * f, 2)
		provTax = round((i + fedTax) * p, 2)
		
		if ( fedTax + provTax == totalTax  )
		
			? 'Base ' , i
			? 'fedtax', fedTax 
			? 'provTax ', provTax 
			exit
		endif
		
		if( fedTax + provTax > totalTax  )
			provTax = totalTax  - fedtax
			? 'Base ' , i
			? 'fedtax', fedTax 
			? 'provTax ', provTax 
			
			exit
		endif
		
	endfor
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform