all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marco Wahl <marcowahlsoft@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: rounding (up)
Date: Thu, 22 Jun 2017 14:34:33 +0200	[thread overview]
Message-ID: <84zid0td46.fsf@tm6592> (raw)
In-Reply-To: 87o9tglbv2.fsf@mat.ucm.es

Uwe Brauer <oub@mat.ucm.es> 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
    

  parent reply	other threads:[~2017-06-22 12:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22  7:28 rounding (up) Uwe Brauer
2017-06-22 12:02 ` John Kitchin
2017-06-22 16:54   ` Uwe Brauer
2017-06-22 12:34 ` Marco Wahl [this message]
2017-06-23  9:50   ` Uwe Brauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84zid0td46.fsf@tm6592 \
    --to=marcowahlsoft@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.