GNU bug report logs - #25557
Documentation of format doesn't describe "g" accurately

Previous Next

Package: emacs;

Reported by: Clément Pit--Claudel <clement.pitclaudel <at> live.com>

Date: Fri, 27 Jan 2017 22:06:01 UTC

Severity: minor

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Clément Pit--Claudel <clement.pitclaudel <at> live.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 25557 <at> debbugs.gnu.org
Subject: bug#25557: Documentation of format doesn't describe "g" accurately
Date: Sat, 28 Jan 2017 11:18:44 -0500
[Message part 1 (text/plain, inline)]
On 2017-01-28 11:01, Eli Zaretskii wrote:
>> Cc: 25557 <at> debbugs.gnu.org
>> From: Clément Pit--Claudel <clement.pitclaudel <at> 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?

No, that always prints decimals.

> 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.

I'm trying to get the shortest representation of a decimal number, rounded to .01, not using scientific/exponential notation.  I'm using values computed in ELisp to produce CSS style sheets, which until recently didn't allow for exponential notation.  I'd like these stylesheets to be readable, so 100% is better 100.00%, and 3.35em is better than 3.35004em. If my code is fed a value of 5000px, I don't want it converted to 5e+3px, because many browsers don't know how to parse that.

Thanks!
Clément.


[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 8 years and 171 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.