translating big numbers

Started by joejoe, October 12, 2019, 06:22:58 PM

Previous topic - Next topic

joejoe

Hi,



I often get this sort of number:



-2.000000000000049e-07



I would like number to just display itself, without the "e-" exponent thing.



I don't mind zeros and I have a big screen and it would love to see the real number.



Would there be an easy way to convert the e number back into normal digits?



Thanks much! :-)

rrq

#1
There is the interesting issue of "precision" in this, i.e. how precises the decimal representation is realative to the actual numberical value held. For example, you might define the following functions:
(define (digits n)
    (let (x 0 m 1)
        (while (!= n (add n m)) (inc x) (setf m (div m 10)))
        x))

(define (P n) (format (string "%0." (digits n) "f") n))

The first function , digits, determines how many fractional digits are representable, in terms of at which fractional position adding 1 at that position doesn't affect the represented number.



One might take that to be how many fractional digits to present, which is what the second function, P, implements. That function returns the number translated to a string (using the "f" format specifier) with a precision of that many fractional digits.



Anything more is kind of senseless, even though the normal "f" translation would happily offer some 76 non-zero fractional digits (which presumably arises due to the mechanics of mapping the number to a decimal representation). But if you want to look at zeroes, you could do
(format "%0.1000f" -2.000000000000049e-07)
:)

joejoe

#2
Ok super, thanks Ralph!



format always seals the deal. I see it now.



Out of curiousity, where are all the numbers coming from after the 0's in the following?


> (format "%0.100f" -2.000000000000049e-07)
"-0.0000002000000000000048878588486791010869758622447989182546734809875488281250000000000000000000000000"


I would think it would be '"-0.00000020000000000000490000...'?