help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using Calc unit conversion functions in an Org Spreadsheet


From: Simon Pugnet
Subject: Using Calc unit conversion functions in an Org Spreadsheet
Date: Wed, 15 Nov 2023 10:52:37 +0000

Hi everyone,

I'm currently trying to use Org mode's spreadsheet functionality to calculate quotes for clients.

For example, I might have a table like this: -

| Task | Time estimate | Rounded hours | CPH | Cost |
|---------+---------------+---------------+-------------+---------------|
| Task #1 | 1 hr + 35 min | 1.75 hr | 50 GBP / hr | 87.5 GBP | | Task #2 | 0 hr + 20 min | 20 min | 50 GBP / hr | 16.666667 GBP |
#+TBLFM: $3=usimplify(ceil($2*4)/4)::$5=usimplify($4*$3)

What I'm trying to do here is to round the time estimate to the nearest 15 minutes, then multiply that figure by the cost per hour (CPH) to produce the final cost.

The problem with the example above is with the ~usimplify~ calls. In the first case, the units get simplified to hours (1.75 hr) and in the second it gets simplified to minutes (20 min). The rounding calculation (ceil(x * 4) / 4) therefore only works when the units are hours as the minutes have no need of rounding. You can see that above: 1 hr + 35 min gets rounded correctly to 1.75 hr, but 0 hr + 20 min does not (it becomes 20 min, but should be 30 min).

I'm therefore trying to replace ~usimplify~ with a function which converts units, i.e. to force the value to be in hours. However I can't find such a function. I found ~math-convert-units~ which seems to do exactly what I need however I can't get it to work and it's not documented. Passing a string expression such as ~(math-convert-units "45 min" 'hr)~ causes the error "Lisp error: (wrong-type-argument number-or-marker-p hr)".

Any help would be greatly appreciated!

Kind regards,

--
Simon Pugnet
https://www.polaris64.net/
PGP key fingerprint: 3BF7 85DE 162C 00C8 FB4D A6FD BA13 59A8 2C0B 3EF9

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]