unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Clément Pit--Claudel" <clement.pitclaudel@live.com>
Cc: 25557@debbugs.gnu.org
Subject: bug#25557: Documentation of format doesn't describe "g" accurately
Date: Sat, 28 Jan 2017 18:01:26 +0200	[thread overview]
Message-ID: <837f5fyy09.fsf@gnu.org> (raw)
In-Reply-To: <1b896eed-9041-83d3-bd46-cde7e534223e@live.com> (message from Clément Pit--Claudel on Sat, 28 Jan 2017 10:45:09 -0500)

> Cc: 25557@debbugs.gnu.org
> From: Clément Pit--Claudel <clement.pitclaudel@live.com>
> Date: Sat, 28 Jan 2017 10:45:09 -0500
> 
> >> I'd like something like this (with a hypothetical %q):
> >>
> >>   (format "%.3q" 3) ⇒ "3"
> >>   (format "%.3q" 3.00) ⇒ "3"
> >>   (format "%.3q" 3.30) ⇒ "3.3"
> >>   (format "%.3q" 3.05) ⇒ "3.05"
> >>   (format "%.3q" 3.352) ⇒ "3.35"
> >>   (format "%.3q" 3100000) ⇒ "3100000"
> >>
> >> This is in fact just the same as 'g', except for the last entry (%g produces "3.1e+06"). Is this achievable?
> > 
> > Yes, if you use "%.7g".  In general, use "%.Ng" if you want up to N
> > digits in the printed representation.
> > 
> > Does that answer your question?
> 
> Almost: though this works for the last example, it breaks the one before the last (I'm looking for a format specifier that would constrain the number of decimals, not the number of digits, so that (format "%.3q" 30.352) would produce "30.35" — maybe all these examples should have had %.2q instead of %.3q, in fact).

Then maybe you want %.2f?

If not, then perhaps you should explain what are you trying to
accomplish?  Why is it important to see 3.35 when the value is 3.352,
but see all the trailing zeros for 3100000?  It sounds like a
contradiction to me.

IME, the most general format is %g, I always use %.Ng when I need N
significant digits no matter what the magnitude of the value, and I
never have any problems.





  reply	other threads:[~2017-01-28 16:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-27 22:05 bug#25557: Documentation of format doesn't describe "g" accurately Clément Pit--Claudel
2017-01-28  8:37 ` Eli Zaretskii
2017-01-28 15:04   ` Clément Pit--Claudel
2017-01-28 15:23     ` Eli Zaretskii
2017-01-28 15:45       ` Clément Pit--Claudel
2017-01-28 16:01         ` Eli Zaretskii [this message]
2017-01-28 16:18           ` Clément Pit--Claudel
2017-01-28 16:25             ` Eli Zaretskii
2017-01-28 19:14               ` Clément Pit--Claudel
2017-01-28 19:31                 ` Eli Zaretskii
2017-01-28 20:06                   ` Clément Pit--Claudel
2017-01-28 20:29                     ` Eli Zaretskii
2017-01-28 20:45                       ` Clément Pit--Claudel

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=837f5fyy09.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=25557@debbugs.gnu.org \
    --cc=clement.pitclaudel@live.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).