emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] org-spreadsheet: formatting chops off units


From: Nick Dokos
Subject: Re: [O] org-spreadsheet: formatting chops off units
Date: Wed, 05 Sep 2012 23:08:15 -0400

Kyle Andrews <address@hidden> wrote:

> Hello everyone,
> 
> I want to use an org-spreadsheet to perform unit conversions for me.
> 
> | Mass (g) | Mass (lb)     |
> |----------+---------------|
> | 300 g    | 0.66138679 lb |
> | 23 kg    | 50.706320 lb  |
> | 50 Mg    | 110231.13 lb  |
> #+TBLFM: $2=uconvert($1, lb)
> 
> 
> I made the table above, but can't figure out how to format the output. I
> tried using the ;%.2f notation shown in the manual, but it cuts the
> units off for some reason.
> 
> Here is what org-table displays with ;%.2f appended onto my table
> formula:
> 
> | Mass (g) | Mass (lb)     |
> |----------+---------------|
> | 300 g    | 0.66          |
> | 23 kg    | 50.71         |
> | 50 Mg    | 110231.13     |
> #+TBLFM: $2=uconvert($1, lb);%.2f
> 
> 
> Here is what I wish appending ;%.2f would cause org-table to display:
> 
> 
> | Mass (g) | Mass (lb)     |
> |----------+---------------|
> | 300 g    | 0.66 lb       |
> | 23 kg    | 50.71 lb      |
> | 50 Mg    | 110231.13 lb  |
> #+TBLFM: $2=uconvert($1, lb);%.2f
> 
> 
> If you type in '0.66138679 lb into calc directly, and press d f 2, calc
> displays 0.66 lb as desired. Is there any reason for the %.2f notation
> chops off the units? Is there some better way to accomplish what I
> want?
> 
> Thanks!
> 
> 
> Note: my spreadsheet uses the wrapper function below to convert units with 
> calc.
> 
> #+begin_src emacs-lisp
> (defmath uconvert (expression new-units)
>     (math-convert-units expression new-units)))
> #+end_src
> 

There might be a better, more local, way of doing it, so take the following as 
an
existence proof: if you customize the variable org-calc-default-modes and change
the calc-float-format to (fix 2), the table will recalculate to your 
expectations.

I don't know how to stitch together the better solution however, so I leave that
as an exercise for you :-)

Nick





reply via email to

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