emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] rounding (up)


From: Marco Wahl
Subject: Re: [O] rounding (up)
Date: Thu, 22 Jun 2017 14:34:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Uwe Brauer <address@hidden> writes:

> Hi
>
> It seems that org-table (and the underlying calc implementation) round
> down not up.
>
>
> Please consider
>
> | 3.25 | 0.4875 |
> |  6.5 |  0.975 |
>
> #+TBLFM: $2=$1*0.15;
>
>
> | 3.25 | 0.49 |
> |  6.5 | 0.97 |
>
> #+TBLFM: $2=$1*0.15;%.2f
>
> Is there a way to obtain
>
> | 3.25 | 0.49 |
> |  6.5 | 0.98 |
>
> #+TBLFM: $2=$1*0.15;%.2f
>
> That is to replace rounding down to rounding up?


(info "(calc) Integer Truncation") has

#v+
The ‘R’ (‘calc-round’) [‘round’ or ‘fround’] command rounds to the
nearest integer.  When the fractional part is .5 exactly, this command
rounds away from zero.  (All other rounding in the Calculator uses this
convention as well.)  Thus ‘3.5 R’ produces 4 but ‘3.4 R’ produces 3;
‘_3.5 R’ produces -4.
#v-

and

#v+
Each of these functions, when written in algebraic formulas, allows a
second argument which specifies the number of digits after the decimal
point to keep.  For example, ‘round(123.4567, 2)’ will produce the
answer 123.46, and ‘round(123.4567, -1)’ will produce 120 (i.e., the
cutoff is one digit to the _left_ of the decimal point).  A second
argument of zero is equivalent to no second argument at all.
#v-

So I suggest the following:

| 3.25 | |
|  6.5 | |
#+TBLFM: $2=round($1*0.15,2);%.2f


Ciao
    Marco
    





reply via email to

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