From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: rounding (up) Date: Thu, 22 Jun 2017 08:02:49 -0400 Message-ID: References: <87o9tglbv2.fsf@mat.ucm.es> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dO0p5-0004Xt-Ib for emacs-orgmode@gnu.org; Thu, 22 Jun 2017 08:02:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dO0p2-00009M-Fd for emacs-orgmode@gnu.org; Thu, 22 Jun 2017 08:02:55 -0400 Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235]:33592) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dO0p2-00009F-Aj for emacs-orgmode@gnu.org; Thu, 22 Jun 2017 08:02:52 -0400 Received: by mail-qk0-x235.google.com with SMTP id r62so9940053qkf.0 for ; Thu, 22 Jun 2017 05:02:52 -0700 (PDT) In-reply-to: <87o9tglbv2.fsf@mat.ucm.es> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Uwe Brauer Cc: emacs-orgmode@gnu.org It appears Emacs uses Banker's rounding (http://wiki.c2.com/?BankersRounding): #+BEGIN_SRC emacs-lisp (list (round 4.5) (round 5.5)) #+END_SRC #+RESULTS: | 4 | 6 | Here is some lightly tested code to get different styles of rounding: #+BEGIN_SRC emacs-lisp (defun custom-round (number &optional N direction) "Round NUMBER to N decimal places. DIRECTION is a symbol of how to round. `round' does Banker's rounding. `ceiling' rounds up. `floor' rounds down. `truncate' rounds towards zero. https://en.wikipedia.org/wiki/Rounding" (setq N (or N 0) direction (or direction 'ceiling)) (let ((m (float (expt 10 (* -1 N))))) (* (funcall direction (/ number m)) m))) (list (custom-round 0.4875 2 'ceiling) (custom-round 0.975 2 'ceiling)) #+END_SRC #+RESULTS: | 0.49 | 0.98 | #+BEGIN_SRC emacs-lisp (list (custom-round 0.4875 2 'floor) (custom-round 0.975 2 'floor)) #+END_SRC #+RESULTS: | 0.48 | 0.97 | Uwe Brauer writes: > Hi > > It seems that org-table (and the underlying calc implementation) round > down not up. > > > Please consider > > | 3.25 | 0.4875 | > | 6.5 | 0.975 | > #+TBLFM: $2=$1*0.15; > > > | 3.25 | 0.49 | > | 6.5 | 0.97 | > #+TBLFM: $2=$1*0.15;%.2f > > Is there a way to obtain > > | 3.25 | 0.49 | > | 6.5 | 0.98 | > #+TBLFM: $2=$1*0.15;%.2f > > That is to replace rounding down to rounding up? > > Thanks > > Uwe Brauer -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu