Lasso Soft Inc. > Home

[lp_decimal_precisionGet]

Linklp_decimal_precisionGet
AuthorBil Corry
CategoryMath
Version8.x
LicensePublic Domain
Posted22 Nov 2005
Updated23 Dec 2005
More by this author...

Description

Returns the precision (aka number of significant digits) of a decimal. Due to random digits in the floating-point math**, it looks for three or more zeros between the significant digits and excludes them and all digits that follow.

Note: Requires [lp_decimal_precisionSet], [lp_string_split]

**
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Sample Usage

'
';
var:'test' = 10;
loop: 66;
	lp_decimal_precisionSet: $test, 64; '\r\n';
	lp_decimal_precisionSet: $test, (lp_decimal_precisionGet: $test); '\r\n';
	lp_decimal_precisionGet: $test; '\r\n\r\n';
	'\r\n';
	$test *= .1;
/loop;
'
';

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:'lp_decimal_precisionGet',
	-description='Returns the precision (aka number of significant digits) of a decimal.',
	-priority='replace',
	-required='number', -copy;
	
	#number = string:(lp_decimal_precisionSet: #number, 64);
	#number->(removetrailing:'0');
	#number = #number->(split:'.')->(get:2);

	local:'temp' = #number;
	#temp->(removeleading:'0');

	#temp = (lp_string_split:#temp,'000',2);
	if: #temp->size == 1;
		return: #number->size;
	else;
		return: #number->size - #temp->(get:2)->size - 3;
	/if;
	
/define_tag;

]

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