Re: Number of digits in a number [82]


[Prev][Next][Index][Thread]

Re: Number of digits in a number [82]



Try this... heavily commented quick&dirty TI-basic, lemme know if it doesn't
work...


assuming the expression is in expr


abs(expr)\->\tmp               ; save expr for future use, we also want a
; positive # for the log(expr)


lbl tsta                       ; slide decimals left
if int(tmp)==tmp               ; do we have an integer?
goto tstb                      ;  <------------------------------------------+
tmp*10\->\tmp                  ; no? slide!                                  |
goto tsta                      ; and chk again...                            |
                               ;                                             |
lbl tstb                       ; slide large magnitudes right                |
if mod(tmp,10)\<>\0            ; if you want 90 to show 2 s.f.'s, remove     |
goto inow                      ; this section and change tstb above to inow -+
tmp/10\->\tmp
goto tstb


lbl inow                       ; we are home free...
int (log(tmp)+1)\->\sfigs      ; sfigs is # of sig figs...


'Course, this only works if expr is nonzero, but who would convert 0?




At 23:29 9/18/96 GMT, you 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.
>---
>Matt Maurano
>mtm@maurano.com
>
>
+--------------------------------------------------------+
| Peter Kolbus                           +1.810.474.0872 |
| ae607@detroit.freenet.org      #include <disclaimer.h> |
+--------------------------------------------------------+
| Due to financial problems, the light at the end of     |
|   the tunnel has been permanently disconnected.        |
|                                                        |
| Who is General Failure, and who gave him permission    |
|    to read drive C?                                    |
|                                                        |
| ***Written using 100% recycled electrons***            |
|         *** (70% post-consumer) ***                    |
+--------------------------------------------------------+


References: