From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#25557: Documentation of format doesn't describe "g" accurately Date: Sat, 28 Jan 2017 18:01:26 +0200 Message-ID: <837f5fyy09.fsf@gnu.org> References: <78ace0d5-59f1-0d7d-1f0e-b589a947d76c@live.com> <83poj7zika.fsf@gnu.org> <83a8abyzqs.fsf@gnu.org> <1b896eed-9041-83d3-bd46-cde7e534223e@live.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1485619335 5178 195.159.176.226 (28 Jan 2017 16:02:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 28 Jan 2017 16:02:15 +0000 (UTC) Cc: 25557@debbugs.gnu.org To: =?UTF-8?Q?Cl=C3=A9ment?= Pit--Claudel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 28 17:02:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXVS4-0000lD-Aw for geb-bug-gnu-emacs@m.gmane.org; Sat, 28 Jan 2017 17:02:08 +0100 Original-Received: from localhost ([::1]:52328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXVS9-00070w-QW for geb-bug-gnu-emacs@m.gmane.org; Sat, 28 Jan 2017 11:02:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXVS3-00070d-HG for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 11:02:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXVRz-0004X2-3p for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 11:02:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51117) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXVRz-0004Wy-03 for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 11:02:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cXVRy-0002rk-OH for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 11:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Jan 2017 16:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25557 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25557-submit@debbugs.gnu.org id=B25557.148561931010998 (code B ref 25557); Sat, 28 Jan 2017 16:02:02 +0000 Original-Received: (at 25557) by debbugs.gnu.org; 28 Jan 2017 16:01:50 +0000 Original-Received: from localhost ([127.0.0.1]:49316 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXVRl-0002rK-PI for submit@debbugs.gnu.org; Sat, 28 Jan 2017 11:01:49 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:47249) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXVRk-0002r7-CD for 25557@debbugs.gnu.org; Sat, 28 Jan 2017 11:01:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXVRa-0004Rw-Sz for 25557@debbugs.gnu.org; Sat, 28 Jan 2017 11:01:43 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:38055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXVRa-0004Rr-PY; Sat, 28 Jan 2017 11:01:38 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2068 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cXVRZ-0002q0-Ag; Sat, 28 Jan 2017 11:01:38 -0500 In-reply-to: <1b896eed-9041-83d3-bd46-cde7e534223e@live.com> (message from =?UTF-8?Q?Cl=C3=A9ment?= Pit--Claudel on Sat, 28 Jan 2017 10:45:09 -0500) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:128722 Archived-At: > Cc: 25557@debbugs.gnu.org > From: Clément Pit--Claudel > 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.