Re: Number of digits in a number [82]
[Prev][Next][Index][Thread]
On 18 Sep 96 at 23:29, Matt Maurano wrote:
> I need to know how to find the number of digits in a number. For
> example:
>
> Number: Digits:
> .1234 4
> 1.23 3
> 9 1
>
> For those interested, this is for the second flag passed to the round(
> function. Its for a convert program I've been working on, and it would
> help if I could round the answer to the number of significant digits.
>
> Please E-Mail responses. Thanks in advance.
>
> P.S.: Right now, the program is ~<1k and does standard to and from
> metric, as well as time conversions. If anyone wants me to post it,
> just E-Mail me.
This was snipped from the New Calc-TI FAQ (which you can get from
www.efd.lth.se/~d96mli/tifaq.txt):
4.7 Q: How do I find the length of a REAL variable?
A: To find the length of the iPart of x:
length= int log x +1
To find the lenght of the fPart of x:
After running this little loop N will contain the number of
decimal digits:
:0->N:While (N<(11-int log x)and(round(x,N)<>x):N+1->N:End
This applies for positive reals only. If x is negative, add 1
for the "-" character and use the abs-value of x in the
formulas above.
If the fPart >0, don't forget to add 1 position for the decimal
point.
<pre>
--
Mattias Lindqvist
d96mli@efd.lth.se
www.efd.lth.se/~d96mli
</pre>
References: