bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#25557: Documentation of format doesn't describe "g" accurately


From: Eli Zaretskii
Subject: bug#25557: Documentation of format doesn't describe "g" accurately
Date: Sat, 28 Jan 2017 18:01:26 +0200

> Cc: address@hidden
> From: Clément Pit--Claudel <address@hidden>
> 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 via email to

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