[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/AF35jtp1    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Jan 7:
1
2
3
4
5
6
7
8
9
10
; floating point rounding

(define (round f n)
  (/ (truncate (+ (* f (expt 10 n)) 0.5)) (expt 10 n)))

(display (round 1000/7 3)) (newline)
(display (round 1000/7 2)) (newline)
(display (round 1000/7 1)) (newline)
(display (round 1000/7 0)) (newline)
(display (round 1000/7 -1)) (newline)


Output:
1
2
3
4
5
142.857
142.86
142.9
143.0
140.0


Create a new paste based on this one


Comments: