all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Using Calc unit conversion functions in an Org Spreadsheet
@ 2023-11-15 10:52 Simon Pugnet
  2023-11-15 16:07 ` Eric S Fraga
  2023-11-16  7:28 ` Michael Heerdegen
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Pugnet @ 2023-11-15 10:52 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1755 bytes --]

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-17  7:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-15 10:52 Using Calc unit conversion functions in an Org Spreadsheet Simon Pugnet
2023-11-15 16:07 ` Eric S Fraga
2023-11-17  7:32   ` Simon Pugnet
2023-11-16  7:28 ` Michael Heerdegen
2023-11-17  7:36   ` Simon Pugnet

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.