Fix Something Annoying

November 6, 2012

My solution to the rounding problem in Standard Scheme is to use the built-in round function to do the hard work, feeding it an appropriate value:

(set! system-round round)

(define (round x . args)
  (if (null? args)
      (system-round x)
      (let ((tens (expt 10 (car args))))
                (/ (system-round (* x tens)) tens))))

Here are some examples:

> (round 123.4567)
> (round 123.4567 2)
> (round 12345.67 -2)
> (round -123.4567 2)

You can run the program at


Pages: 1 2

3 Responses to “Fix Something Annoying”

  1. Chris said

    I implemented the Gasoline Mileage Log in Erlang, and in doing so was annoyed that I couldn’t find an Erlang function that works like Clojure’s core/partition. Here’s my fix.

  2. […] today’s Programming Praxis exercise, our goal is to fix something that annoys us in our programming […]

  3. I created a library to resolve my annoyances with the Parsec library. For more information, see the blog post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: