From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id kM8pEsd2bF8XEgAA0tVLHw (envelope-from ) for ; Thu, 24 Sep 2020 10:36:55 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id INXUDcd2bF9UNgAAbx9fmQ (envelope-from ) for ; Thu, 24 Sep 2020 10:36:55 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3CC9C9402A4 for ; Thu, 24 Sep 2020 10:36:54 +0000 (UTC) Received: from localhost ([::1]:59220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLOcO-0005gN-1p for larch@yhetil.org; Thu, 24 Sep 2020 06:36:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLNpH-0006Ki-OG for emacs-orgmode@gnu.org; Thu, 24 Sep 2020 05:46:10 -0400 Received: from mailer-211-161.hitrost.net ([91.185.211.161]:21748) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLNpB-0000Vj-7d for emacs-orgmode@gnu.org; Thu, 24 Sep 2020 05:46:07 -0400 Received: from [84.20.244.182] (helo=Tauriel) by b1.hitrost.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1kLNPQ-002tlf-QF; Thu, 24 Sep 2020 11:19:24 +0200 References: <3444a52f-36a7-6e9d-46b9-272dddc7a3ef@grinta.net> User-agent: mu4e 0.9.19; emacs 25.3.2 From: Christian Moe To: emacs-orgmode@gnu.org Subject: Re: org-tables with monetary amounts In-reply-to: <3444a52f-36a7-6e9d-46b9-272dddc7a3ef@grinta.net> Date: Thu, 24 Sep 2020 11:17:28 +0200 Message-ID: <87wo0jttxz.fsf@christianmoe.com> MIME-Version: 1.0 Content-Type: text/plain X-GeoIP: Country [IP], SI [84.20.244.182] X-Antivirus-Scanner: Clean mail though you should still use an Antivirus Received-SPF: pass client-ip=91.185.211.161; envelope-from=mail@christianmoe.com; helo=mailer-211-161.hitrost.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/24 05:19:25 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, LOTS_OF_MONEY=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.01 X-TUID: 7WFTUjLs6QRq Hi, Parsing numbers followed by currencies is sort of supported already through Calc's operations on units. (Calc is the built-in emacs calculator that powers the spreadsheet function of Org tables). I haven't used this or explored it much, but my impression is that it could be made more useful than it currently is. Here are a couple of things you can do fairly easily. If you're only working with one currency and just want it to show up automatically, the following calculation will give you 59.97 USD in the third column right out of the box, without even requiring you to define it as a unit first. | 50 USD | 8.97 USD | 59.97 USD | #+TBLFM: $3=$1+$2 Adding undefined currencies together will result in an expression like "3 USD + 4 EUR". However, if you define the currencies as units based on exchange rates, you can get conversion as part of arithmetic operations. E.g. in Calc, - put `1' on top of the stack - then do `u d EUR' to define the euro as your unit currency (for example) - then define e.g. US dollars: Today's rate is 1 USD = 0.86 EUR. - hit apostrophe to enter algebraic mode and enter `0.86 EUR' (today's rate: 1 USD = 0.86 EUR) - now do `u d USD' to define the rate Now, with the Calc command to simplify units, you can add dollars to euros and get the result in whichever currency comes first in the algebraic expression | 3 USD | 4 EUR | 6.58 EUR | #+tblfm: $3=usimplify($2+$1) | 3 USD | 4 EUR | 7.6511628 USD | #+tblfm: $3=usimplify($1+$2) I don't use this functionality, so I don't have answers to all the questions you'll now have -- including how to get the desired precision without lopping off the currency unit in the last example! There are ways to enter user-defined units permanently. But exchange rates change, so to use this functionality on a daily basis, you'll want to have some kind of function to pull exchange rates and update the currency unit definitions in the Calc init file. Apart from `usimplify', most Calc functions on units appear (?) to be missing corresponding algebraic versions that you can use in Calc expressions in Org tables, which limits the usefulness. Org tables don't seem to have any specific formula syntax for leveraging Calc unit operations apart from what happens to work out of the box. This might be an area for improvement, though I'm not sure what to ask for. Yours, Christian Daniele Nicolodi writes: > Hello, > > I often use org-tables to work with monetary amounts. It would be very > nice to have a couple of functionalities common in this domain: > > - fixed precision arithmetic, namely derive the precision of the results > from the precision of the arguments (I think that calc can do this), > > - support for parsing numbers followed by currencies, > > - correct alignment for monetary values. > > I had a quick look around, but I haven't found anything that implements > those things. Has anyone some secret code that they would like to share? > > Thank you! > > Cheers, > Dan