Lasso Soft Inc. > Home

[math_roundto]

Linkmath_roundto
AuthorJason Huck
CategoryMath
Version8.5.x
LicensePublic Domain
Posted19 May 2007
Updated24 May 2007
More by this author...

Description

Given two numbers, rounds the first number to the closest multiple of the second number.

Sample Usage

math_roundto(51, 5);

-> 50

math_roundto(53, 5);

-> 55

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'roundto',
	-namespace='math_',
	-req='n',
	-req='m',
	-priority='replace',
	-description='Rounds the first number to the closest multiple of the second number.'
);
	local('nxt') = #n - (#n % #m) + #m;
	local('lst') = #nxt - #m;
	local('avg') = (#nxt + #lst) / 2.0;
	
	if(#n % #m);
		local('out') = (#n >= #avg ? #nxt | #lst);
	else;
		local('out') = #n;
	/if;
	
	return(#out);
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft