* Floating-point formatting string
@ 2007-02-14 1:17 Vinicius Jose Latorre
2007-02-14 1:28 ` Juanma Barranquero
2007-02-14 1:36 ` Chong Yidong
0 siblings, 2 replies; 8+ messages in thread
From: Vinicius Jose Latorre @ 2007-02-14 1:17 UTC (permalink / raw)
To: emacs-devel
Hi,
It seems that there is a problem with floating-point formatting string
in Emacs 22.
Type
M-: (format "%03.3f" 1.2) RET
==> "1.200"
Shouldn't it be "001.200"?
M-: (format "% 3.3f" 1.2) RET
==> " 1.200"
Shouldn't it be " 1.200"?
It's working for integer:
M-: (format "%03d" 1) RET
==> "001" ; OK
M-: (format "% 3d" 1) RET
==> " 1" ; OK
Vinicius
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Floating-point formatting string
2007-02-14 1:17 Floating-point formatting string Vinicius Jose Latorre
@ 2007-02-14 1:28 ` Juanma Barranquero
2007-02-14 1:40 ` Vinicius Jose Latorre
2007-02-14 1:36 ` Chong Yidong
1 sibling, 1 reply; 8+ messages in thread
From: Juanma Barranquero @ 2007-02-14 1:28 UTC (permalink / raw)
To: Vinicius Jose Latorre; +Cc: emacs-devel
On 2/14/07, Vinicius Jose Latorre <viniciusjl@ig.com.br> wrote:
> Type
> M-: (format "%03.3f" 1.2) RET
> ==> "1.200"
>
> Shouldn't it be "001.200"?
>From format's docstring:
The basic structure of a %-sequence is
% <flags> <width> <precision> character
where flags is [- #0]+, width is [0-9]+, and precision is .[0-9]+
You're saying "flag = 0, width = 3, precision = 3". That overflows the
width = 3.
Try
(format "%07.3f" 1.2) => "001.200"
Juanma
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Floating-point formatting string
2007-02-14 1:17 Floating-point formatting string Vinicius Jose Latorre
2007-02-14 1:28 ` Juanma Barranquero
@ 2007-02-14 1:36 ` Chong Yidong
2007-02-14 1:42 ` Vinicius Jose Latorre
2007-02-14 16:26 ` Stuart D. Herring
1 sibling, 2 replies; 8+ messages in thread
From: Chong Yidong @ 2007-02-14 1:36 UTC (permalink / raw)
To: Vinicius Jose Latorre; +Cc: emacs-devel
Vinicius Jose Latorre <viniciusjl@ig.com.br> writes:
> Hi,
>
>
> It seems that there is a problem with floating-point formatting string
> in Emacs 22.
>
> Type
> M-: (format "%03.3f" 1.2) RET
> ==> "1.200"
>
> Shouldn't it be "001.200"?
The Elisp manual says, of the width specification:
If the printed representation of the object contains fewer
characters than this width, then it is padded.
In this case, the 03 refers to the width of the entire string "1.200",
which is 5 > 3.
For example,
M-: (format "%08.3f" 1.2)
==> 0001.200
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Floating-point formatting string
2007-02-14 1:28 ` Juanma Barranquero
@ 2007-02-14 1:40 ` Vinicius Jose Latorre
0 siblings, 0 replies; 8+ messages in thread
From: Vinicius Jose Latorre @ 2007-02-14 1:40 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: emacs-devel
Juanma Barranquero wrote:
> On 2/14/07, Vinicius Jose Latorre <viniciusjl@ig.com.br> wrote:
>
>> Type
>> M-: (format "%03.3f" 1.2) RET
>> ==> "1.200"
>>
>> Shouldn't it be "001.200"?
>
>> From format's docstring:
>
> The basic structure of a %-sequence is
> % <flags> <width> <precision> character
> where flags is [- #0]+, width is [0-9]+, and precision is .[0-9]+
>
> You're saying "flag = 0, width = 3, precision = 3". That overflows the
> width = 3.
>
> Try
>
> (format "%07.3f" 1.2) => "001.200"
Ok, width of ALL string representation.
I thought it was the integer part width only.
Thanks,
Vinicius
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Floating-point formatting string
2007-02-14 1:36 ` Chong Yidong
@ 2007-02-14 1:42 ` Vinicius Jose Latorre
2007-02-14 16:26 ` Stuart D. Herring
1 sibling, 0 replies; 8+ messages in thread
From: Vinicius Jose Latorre @ 2007-02-14 1:42 UTC (permalink / raw)
To: Chong Yidong; +Cc: emacs-devel
Chong Yidong wrote:
> Vinicius Jose Latorre <viniciusjl@ig.com.br> writes:
>
>
>> Hi,
>>
>>
>> It seems that there is a problem with floating-point formatting string
>> in Emacs 22.
>>
>> Type
>> M-: (format "%03.3f" 1.2) RET
>> ==> "1.200"
>>
>> Shouldn't it be "001.200"?
>>
>
> The Elisp manual says, of the width specification:
>
> If the printed representation of the object contains fewer
> characters than this width, then it is padded.
>
> In this case, the 03 refers to the width of the entire string "1.200",
> which is 5 > 3.
>
> For example,
>
> M-: (format "%08.3f" 1.2)
> ==> 0001.200
>
Ok, thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Floating-point formatting string
2007-02-14 1:36 ` Chong Yidong
2007-02-14 1:42 ` Vinicius Jose Latorre
@ 2007-02-14 16:26 ` Stuart D. Herring
2007-02-14 16:32 ` Andreas Schwab
2007-02-14 16:35 ` Juanma Barranquero
1 sibling, 2 replies; 8+ messages in thread
From: Stuart D. Herring @ 2007-02-14 16:26 UTC (permalink / raw)
To: Chong Yidong; +Cc: Vinicius Jose Latorre, emacs-devel
> In this case, the 03 refers to the width of the entire string "1.200",
which is 5 > 3.
>
> For example,
>
> M-: (format "%08.3f" 1.2)
> ==> 0001.200
That doesn't quite explain Vinicius' other examples; in particular,
M-: (format "% 3.3f" 1.2)
==> " 1.200"
which has been padded even though it's longer than 3 characters without
the space.
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Floating-point formatting string
2007-02-14 16:26 ` Stuart D. Herring
@ 2007-02-14 16:32 ` Andreas Schwab
2007-02-14 16:35 ` Juanma Barranquero
1 sibling, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2007-02-14 16:32 UTC (permalink / raw)
To: herring; +Cc: Chong Yidong, Vinicius Jose Latorre, emacs-devel
"Stuart D. Herring" <herring@lanl.gov> writes:
> That doesn't quite explain Vinicius' other examples; in particular,
>
> M-: (format "% 3.3f" 1.2)
> ==> " 1.200"
>
> which has been padded even though it's longer than 3 characters without
> the space.
That's not padding, it's the sign. Similar to the '+' flag.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Floating-point formatting string
2007-02-14 16:26 ` Stuart D. Herring
2007-02-14 16:32 ` Andreas Schwab
@ 2007-02-14 16:35 ` Juanma Barranquero
1 sibling, 0 replies; 8+ messages in thread
From: Juanma Barranquero @ 2007-02-14 16:35 UTC (permalink / raw)
To: herring; +Cc: Chong Yidong, Vinicius Jose Latorre, emacs-devel
On 2/14/07, Stuart D. Herring <herring@lanl.gov> wrote:
> That doesn't quite explain Vinicius' other examples; in particular,
>
> M-: (format "% 3.3f" 1.2)
> ==> " 1.200"
>
> which has been padded even though it's longer than 3 characters without
> the space.
That's not padding. The flag " " does not mean "pad with spaces", but
"inserts a space for positive numbers". That helps with columns, if
the number can also be negative:
ELISP> (format "%3.3f" 1.2)
"1.200"
ELISP> (format "%3.3f" -1.2)
"-1.200"
ELISP> (format "% 3.3f" 1.2)
" 1.200"
ELISP> (format "% 3.3f" -1.2)
"-1.200"
Space-padding is specified by using no flag:
ELISP> (format "%6.3f" -1.2)
"-1.200"
ELISP> (format "%6.3f" 1.2)
" 1.200"
Juanma
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-02-14 16:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-14 1:17 Floating-point formatting string Vinicius Jose Latorre
2007-02-14 1:28 ` Juanma Barranquero
2007-02-14 1:40 ` Vinicius Jose Latorre
2007-02-14 1:36 ` Chong Yidong
2007-02-14 1:42 ` Vinicius Jose Latorre
2007-02-14 16:26 ` Stuart D. Herring
2007-02-14 16:32 ` Andreas Schwab
2007-02-14 16:35 ` Juanma Barranquero
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.