From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Incorrect sum of times in table Date: Mon, 01 Jul 2013 16:49:08 -0400 Message-ID: <87ppv2atvf.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utl2I-0000dQ-2j for emacs-orgmode@gnu.org; Mon, 01 Jul 2013 16:49:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Utl2D-0005J2-He for emacs-orgmode@gnu.org; Mon, 01 Jul 2013 16:49:21 -0400 Received: from plane.gmane.org ([80.91.229.3]:52089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utl2D-0005Hx-9v for emacs-orgmode@gnu.org; Mon, 01 Jul 2013 16:49:17 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Utl2C-0004RH-Bk for emacs-orgmode@gnu.org; Mon, 01 Jul 2013 22:49:16 +0200 Received: from pool-108-7-96-134.bstnma.fios.verizon.net ([108.7.96.134]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 01 Jul 2013 22:49:16 +0200 Received: from ndokos by pool-108-7-96-134.bstnma.fios.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 01 Jul 2013 22:49:16 +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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Paul Stansell writes: > Hello, > > I noticed a case where the sum of two times in a table does not give > the correct answer. > > To see this, create an org file with the following lines: > > | 0:00:31 | > | 0:00:30 | > |---------| > | | > > Open it and type C-+ C-y in the empty cell of the table. The answer > inserted is 0:01:00 instead of 0:01:01. > I think you mean C-c +. The problem is that these things are calculated as decimal hours, using floating point arithmetic and you get truncation towards 0 when the value is printed out as an integer. The format in org-table-sum is (format "%d:%02d:%02d" h m s) but s is 0.9999... and it gets formatted as 0. It might be better to use (format "%.0f:%02.0f:%02.0f" h m s) i.e. as floating point with no places after the decimal point (in which case the decimal point does not seem to be output). But there may be other problems that I have not thought of. It might be even better to round the floating point number to the nearest integer and use %d formats instead: (format "%d:%02d:%02d" (round h) (round m) (round s)) -- Nick