[lp_decimal_precisionGet]

Description

Link: [lp_decimal_precisionGet]
Author: Bil Corry
Category: Math
Version: 8.x
License: Public Domain
Posted: Nov. 22, 2005
Updated: Dec. 23, 2005
More by this author...
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

Parameters

-number decimal, required A decimal number that you want to know how many places you need to show the entire number.

Sample Usage

'<pre>';
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;
'</pre>';
						

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[

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

none

Email:


Password:



Newest

Most Popular