convert to scientific notation
randall at randallreetz.com
Tue Apr 21 03:13:30 EDT 2009
Just devide the number by the number of digits in the truncated number minus one, multiplied by ten.
put (n/(((the number of chars in (trunc(n)))-1)*10)&&"x 10^"&((the number of chars in (trunc(n)))-1)
From: "James Hurley" <jhurley0305 at sbcglobal.net>
To: use-revolution at lists.runrev.com
Sent: 4/20/2009 11:18 PM
Subject: Re:convert to scientific notation
> Message: 3
> Date: Mon, 20 Apr 2009 16:53:05 -0700
> From: Randall Lee Reetz <randall at randallreetz.com>
> Subject: convert to scientific notation
> To: How to use Revolution <use-revolution at lists.runrev.com>
> Message-ID: <F40AB9D0-D69A-4D6D-A106-FAFAD24C7036 at randallreetz.com>
> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
> I can't remember how to use power function "^" to find the nth root
> of a number. To find the 2ndth root of a number we can use the "sqrt
> ()" function. But to find the nth root????
> For instance, lets say I want to convert a number to scientific
> notation (the 10th root of that number)... I used to know how to use
> the power function to do this. Anyone remember how to do it?
> I tried to get the 10th root (scientific notation) of 100 (which
> should = 2) by: 100^(1/10) ... but that isn't it.
> Any ideas? I feel brain dead.
Here is the function I have always used--see Turtle Graphics
function sci tNum,sigFigures
if tNum < 0 then
put "-" into sign
else put empty into sign
put abs(tNum) into tNum
if sigFigures is empty then put 3 into sigFigures --Default
put 0 into count
if tNum >= 1 then
repeat until tNum < 10
divide tNum by 10
add 1 to count
put round((10^(sigFigures-1))*tNum)/10^(sigFigures-1) into tNum
return sign & (char 1 to sigFigures + 1 of tNum) &"*10^" & count
if tNum < 1 then
repeat until tNum >= 1
multiply tNum by 10
add 1 to count
return sign & (char 1 to sigFigures + 1 of tNum) & "*10^-" & count
Brute force, but functional.
[truncated by sender]
More information about the use-livecode