[prev in list] [next in list] [prev in thread] [next in thread] 

List:       racket-users
Subject:    [plt-scheme] Printing
From:       mcj4 () kent ! ac ! uk (Matt Jadud)
Date:       2005-10-15 8:12:32
Message-ID: 4350B9F0.5050701 () kent ! ac ! uk
[Download RAW message or body]

You could do:

(define (decimal-places n places)
   (* 1.0 (/ (floor (* n (expt 10 places))) (expt 10 places))))

... or something similar. I thought there was some kind of interpolation 
library in Planet that allowed something like your first example? (I 
could be making that up, though.)

M

Evan Farrer wrote:
> This is a really simple question, but I can't find the answer anywhere (help-desk, \
> google, etc.).  How do you control, how many decimal places get printed with a \
> floating pointer number. 
> For example I want somthing like:
> 
> (define PI 3.1479)
> 
> (printf "~1.2a\n" PI) => 3.14
> 
> or
> 
> (printf "~a\n" (decimal-places PI 2)) => 3.14
> 
> 
> Thanks,
> 
> Evan
> 
> 
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic