emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Format a whole column using ";%.2f" in orgtbl?
@ 2012-06-15 14:34 AW
  2012-06-15 17:01 ` Michael Brand
  0 siblings, 1 reply; 5+ messages in thread
From: AW @ 2012-06-15 14:34 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I'm using radiotables and would like to get all numbers of column 1 with two 
digits after the decimal separator. My example below leads to an error, but it 
may explain what I'd like to receive:

Input:

| 100 | Value |
| 150 | Value |
#+TBLFM: $1=%s;%.2f

Desired outoput:

| 100.00 | Value |
| 150.00 | Value |
#+TBLFM: $1=%s;%.2f

I also tried to use :fmt (1 %s;%.2f)
while exporting to LaTeX, but in vain. 

Regards,
Alexander

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

* Re: Format a whole column using ";%.2f" in orgtbl?
  2012-06-15 14:34 Format a whole column using ";%.2f" in orgtbl? AW
@ 2012-06-15 17:01 ` Michael Brand
  2012-06-21 10:15   ` AW
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Brand @ 2012-06-15 17:01 UTC (permalink / raw)
  To: AW; +Cc: emacs-orgmode

Hi Alexander

On Fri, Jun 15, 2012 at 4:34 PM, AW <alexander.willand@t-online.de> wrote:
> [...]
>
> Desired outoput:
>
> | 100.00 | Value |
> | 150.00 | Value |
> #+TBLFM: $1=%s;%.2f
>
> [...]

What you tried would be

| 100.00 | Value |
| 150.00 | Value |
#+TBLFM: $1=$0;%.2f

$0 is the current table field. What I recommend is

| 100.00 | Value |
| 150.00 | Value |
#+TBLFM: $1 = $0 +.0; f-2

because of the behavior I explained in the tables shown here:
http://orgmode.org/worg/org-faq.html#table-float-fraction

Michael

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

* Re: Format a whole column using ";%.2f" in orgtbl?
  2012-06-15 17:01 ` Michael Brand
@ 2012-06-21 10:15   ` AW
  2012-06-21 16:29     ` Michael Brand
  0 siblings, 1 reply; 5+ messages in thread
From: AW @ 2012-06-21 10:15 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Michael Brand

Am Freitag, 15. Juni 2012, 19:01:35 schrieb Michael Brand:
> Hi Alexander
> 
> On Fri, Jun 15, 2012 at 4:34 PM, AW <alexander.willand@t-online.de> wrote:
> > [...]
> > 
> > Desired outoput:
> > | 100.00 | Value |
> > | 150.00 | Value |
> > 
> > #+TBLFM: $1=%s;%.2f
> > 
> > [...]
> 
> What you tried would be
> 
> | 100.00 | Value |
> | 150.00 | Value |
> 
> #+TBLFM: $1=$0;%.2f
> 
> $0 is the current table field. What I recommend is
> 
> | 100.00 | Value |
> | 150.00 | Value |
> 
> #+TBLFM: $1 = $0 +.0; f-2
> 
> because of the behavior I explained in the tables shown here:
> http://orgmode.org/worg/org-faq.html#table-float-fraction
> 
> Michael

O.K., thank you very much for your help. This is a nice trick!

Unfortunately, my tables have other formulas than only one:

| Values | Desc. |
|--------+-------|
| 100.00 | Value |
| 150.00 | Value |
|   250. | sum   |
|--------+-------|
|   500. | End   |
#+TBLFM: @4$1=@2$1+@3$1::@5$1=vsum(@I..@II)::$1=$0 +.0; f-2

I get at least every number in column 1 with a dot, but without ".00", as 
needed: 

*Do I have to ad '; f-2' to every formula?* 

And besides that, I've never seen this description "f-2". Is it explained 
somewhere for non-mathematicians? You know, if there are differences between 
this and ";%.2f", I should better be aware of them. 

Regards

Alexander

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

* Re: Format a whole column using ";%.2f" in orgtbl?
  2012-06-21 10:15   ` AW
@ 2012-06-21 16:29     ` Michael Brand
  2012-06-21 20:18       ` AW
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Brand @ 2012-06-21 16:29 UTC (permalink / raw)
  To: AW; +Cc: emacs-orgmode

Hi Alexander

On Thu, Jun 21, 2012 at 12:15 PM, AW <alexander.willand@t-online.de> wrote:
> | Values | Desc. |
> |--------+-------|
> | 100.00 | Value |
> | 150.00 | Value |
> |   250. | sum   |
> |--------+-------|
> |   500. | End   |
> #+TBLFM: @4$1=@2$1+@3$1::@5$1=vsum(@I..@II)::$1=$0 +.0; f-2
>
> I get at least every number in column 1 with a dot, but without ".00", as
> needed:

The ending dot is Calc syntax and means a float with fraction 0.

> *Do I have to ad '; f-2' to every formula?*

Yes, else the Calc result is inserted without change. There is a
formula debugger that shows the formatting steps nicely: "C-c {"

The "+.0" is necessary too to convert Calc integer to Calc float for
some cases as shown in the example tables here:
http://orgmode.org/worg/org-faq.html#table-float-fraction

All together:
#+TBLFM: @4$1=@2$1+@3$1 +.0; f-2::@5$1=vsum(@I..@II) +.0; f-2::$1=$0 +.0; f-2

This is what I recommend just in general and what I do always myself
as a habit because it can deal also with higher precision or the case
when those of the fields resulting in an empty string should remain
empty instead of a "0.00". If you don't want to be prepared for all
that, for your current example you can still use just

#+TBLFM: @4$1=@2$1+@3$1;%.2f::@5$1=vsum(@I..@II);%.2f::$1=$0;%.2f

> And besides that, I've never seen this description "f-2". Is it explained
> somewhere for non-mathematicians?

For an explanation see the URLs to the Calc manual mentioned here
http://orgmode.org/worg/org-faq.html#table-float-fraction
after "For f3 and f-3 see `d f' (`calc-fix-notation')".

Michael

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

* Re: Format a whole column using ";%.2f" in orgtbl?
  2012-06-21 16:29     ` Michael Brand
@ 2012-06-21 20:18       ` AW
  0 siblings, 0 replies; 5+ messages in thread
From: AW @ 2012-06-21 20:18 UTC (permalink / raw)
  To: Michael Brand; +Cc: emacs-orgmode

Hi Michael

Thank you very much for your quick, qualified and 	satisfying answer!

Alexander

> Hi Alexander
> 
> On Thu, Jun 21, 2012 at 12:15 PM, AW <alexander.willand@t-online.de> wrote:
> > | Values | Desc. |
> > |
> > |--------+-------|
> > |
> > | 100.00 | Value |
> > | 150.00 | Value |
> > | 
> > |   250. | sum   |
> > |
> > |--------+-------|
> > |
> > |   500. | End   |
> > 
> > #+TBLFM: @4$1=@2$1+@3$1::@5$1=vsum(@I..@II)::$1=$0 +.0; f-2
> > 
> > I get at least every number in column 1 with a dot, but without ".00", as
> 
> > needed:
> The ending dot is Calc syntax and means a float with fraction 0.
> 
> > *Do I have to ad '; f-2' to every formula?*
> 
> Yes, else the Calc result is inserted without change. There is a
> formula debugger that shows the formatting steps nicely: "C-c {"
> 
> The "+.0" is necessary too to convert Calc integer to Calc float for
> some cases as shown in the example tables here:
> http://orgmode.org/worg/org-faq.html#table-float-fraction
> 
> All together:
> #+TBLFM: @4$1=@2$1+@3$1 +.0; f-2::@5$1=vsum(@I..@II) +.0; f-2::$1=$0 +.0;
> f-2
> 
> This is what I recommend just in general and what I do always myself
> as a habit because it can deal also with higher precision or the case
> when those of the fields resulting in an empty string should remain
> empty instead of a "0.00". If you don't want to be prepared for all
> that, for your current example you can still use just
> 
> #+TBLFM: @4$1=@2$1+@3$1;%.2f::@5$1=vsum(@I..@II);%.2f::$1=$0;%.2f
> 
> > And besides that, I've never seen this description "f-2". Is it explained
> > somewhere for non-mathematicians?
> 
> For an explanation see the URLs to the Calc manual mentioned here
> http://orgmode.org/worg/org-faq.html#table-float-fraction
> after "For f3 and f-3 see `d f' (`calc-fix-notation')".
> 
> Michael

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

end of thread, other threads:[~2012-06-21 20:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-15 14:34 Format a whole column using ";%.2f" in orgtbl? AW
2012-06-15 17:01 ` Michael Brand
2012-06-21 10:15   ` AW
2012-06-21 16:29     ` Michael Brand
2012-06-21 20:18       ` AW

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).