Page 1 of 1 1
Topic Options
#190077 - 2008-10-09 02:03 PM Display low values
Statler Offline
Fresh Scripter

Registered: 2004-09-25
Posts: 11
I have to write a kix script wich transform and display very small messurement values (like 0.00001 %). But the script converts the values like 1E10-5. But I canīt use this kind of values. What can I do to force the script to display all values like this: 0.00001% ??

Thank you for help...

Thomas

Top
#190079 - 2008-10-09 02:26 PM Re: Display low values [Re: Statler]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Before using the variable try converting it to Double.
For instance:
 Code:
Dim $x
CDbl($x)

Top
#190086 - 2008-10-09 05:50 PM Re: Display low values [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Also, a good trick is to force calculations to double-precision, such as

0.0 + $Value = "a double-precision addition"
or
1.0 * $Value = "a double-precision multiplication"

$Value can be any value or formula. Because the first value is a double, Kix will treat all remaining values as doubles.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190108 - 2008-10-13 10:28 AM Re: Display low values [Re: Glenn Barnas]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Maybe I'm missing something guys, but the number is *already* a double, it's the display that's a bit of a problem.

I'm pretty sure that this has come up before, so you can search for a solution, but here is a quick 'n' dirty way of doing it:
 Code:
Break ON
 
$i=1.0
for $t=1 to 10
	$i=$i/10
	TrimZero(FormatNumber($i,10)) @CRLF
next
 
Function TrimZero($s)
	While(Len($s)>1 AND Right($S,1)="0" AND Right($s,2)<>".0")
		$s=Left($s,-1)
	Loop
	$TrimZero=$s
EndFunction

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.079 seconds in which 0.041 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org