<brlspam@sperience.com> wrote:
+---------------
| mehdia82@my-deja.com writes:
|
| > I get the result 1/625, when I put expt (/ 1.0 x)instead of expt (/ 1 x)
| > in the code I get 1.6000000000000005e-3 so how can I do to have the
| > result in the format 0.0016
|
| The problem with the latter is that you are using inexact numbers in
| your calculation. You should use exact numbers (yielding 1/625), and then
| apply exact->inexact at the end if you want a more accurate inexact result.
+---------------
Unfortunately, the Scheme standard(s) don't specify anything directly
corresponding to C-style "printf" or Common Lisp-style "format". However,
there's an implementation of CL-style "format" in the SLIB library
distributed by Aubrey Jaffer which runs on top of most Schemes:
http://swissnet.ai.mit.edu/~jaffer/SLIB.html
Given that (or some other implementation of "format"), then it's simple:
> (require 'format)
> 1/625
1.6e-3 ; or 1/625, depending on your Scheme
> (format #t "~6,4f~%" 1/625)
0.0016
#t
>
-Rob
-----
Rob Warnock, 8L-846 rpw3@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. FAX: 650-933-0511
Mountain View, CA 94043 PP-ASEL-IA