From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marco Wahl Subject: Re: rounding (up) Date: Thu, 22 Jun 2017 14:34:33 +0200 Message-ID: <84zid0td46.fsf@tm6592> References: <87o9tglbv2.fsf@mat.ucm.es> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dO1Ju-00071O-F2 for emacs-orgmode@gnu.org; Thu, 22 Jun 2017 08:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dO1Jq-0003W6-H6 for emacs-orgmode@gnu.org; Thu, 22 Jun 2017 08:34:46 -0400 Received: from [195.159.176.226] (port=38245 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dO1Jq-0003Vf-Ae for emacs-orgmode@gnu.org; Thu, 22 Jun 2017 08:34:42 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dO1Jj-0001oX-0J for emacs-orgmode@gnu.org; Thu, 22 Jun 2017 14:34:35 +0200 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: emacs-orgmode@gnu.org 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? (info "(calc) Integer Truncation") has #v+ The ‘R’ (‘calc-round’) [‘round’ or ‘fround’] command rounds to the nearest integer. When the fractional part is .5 exactly, this command rounds away from zero. (All other rounding in the Calculator uses this convention as well.) Thus ‘3.5 R’ produces 4 but ‘3.4 R’ produces 3; ‘_3.5 R’ produces -4. #v- and #v+ Each of these functions, when written in algebraic formulas, allows a second argument which specifies the number of digits after the decimal point to keep. For example, ‘round(123.4567, 2)’ will produce the answer 123.46, and ‘round(123.4567, -1)’ will produce 120 (i.e., the cutoff is one digit to the _left_ of the decimal point). A second argument of zero is equivalent to no second argument at all. #v- So I suggest the following: | 3.25 | | | 6.5 | | #+TBLFM: $2=round($1*0.15,2);%.2f Ciao Marco