Page 1 of 1

format %e problem

Posted: Tue Dec 25, 2012 8:31 am
by dexter
Hi guys

in newlisp docs

Code: Select all

(format "%e" 123456789)        → "1.234568e+08"
But when I reverse this

Code: Select all

> (int 1.234568e+08)
123456800
Got the different results
Why is this happend?

---
newLISP v.10.4.4 on OSX IPv4/6. 64bits

Re: format %e problem

Posted: Tue Dec 25, 2012 9:32 am
by johu

Code: Select all

> (format "%e" 123456789)
"1.234568e+008"
> (format "%.6e" 123456789)
"1.234568e+008"
> (int 1.234568e+008)
123456800
> (format "%.7e" 123456789)
"1.2345679e+008"
> (int 1.2345679e+008)
123456790
> (format "%.8e" 123456789)
"1.23456789e+008"
> (int 1.23456789e+008)
123456789
Please read format.

Re: format %e problem

Posted: Tue Dec 25, 2012 9:51 am
by HPW

Code: Select all

(format "%e" 123456789)
Without precision parameter it uses a default precision, so t gets rounded.
(Not mentioned in the doc)

Re: format %e problem

Posted: Tue Dec 25, 2012 1:24 pm
by dexter
oh God

thanks guys