how to i get comma seperated integer/float point with "Format"
example 10,000.5 - > 10,000.5
what other arguments other than ':D' should be included to cause that
effect.
(format t "~:D,etc,etc" 10000.5)
Thanking you in advance.
George E Tasso
On Apr 10, 6:09 am, ·······@gmail.com wrote:
> how to i get comma seperated integer/float point with "Format"
>
> example 10,000.5 - > 10,000.5
cl-l10n provides this functionality with format-number (and a suitable
locale such as en_US or en_GB)
eg.
(setf cl-l10n:*locale* (cl-l10n:locale "en_GB"))
(format nil "~/cl-l10n:format-number/" 10000.50)
=> "10,000.50"
sean.
·······@gmail.com writes:
> how to i get comma seperated integer/float point with "Format"
>
> example 10,000.5 - > 10,000.5
>
> what other arguments other than ':D' should be included to cause that
> effect.
>
> (format t "~:D,etc,etc" 10000.5)
>
> Thanking you in advance.
Use the monetary format ~$, which is useful also on non monetary values.
--
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org
Pascal Bourguignon <···@informatimago.com> wrote:
+---------------
| ·······@gmail.com writes:
| > how to i get comma seperated integer/float point with "Format"
| > example 10,000.5 - > 10,000.5
| > what other arguments other than ':D' should be included to cause that
| > effect.
| > (format t "~:D,etc,etc" 10000.5)
|
| Use the monetary format ~$, which is useful also on non monetary values.
+---------------
As far as I know [and I searched CLHS "22.3.3.4 Tilde Dollarsign:
Monetary Floating-Point" pretty closely], monetary format doesn't
provide for printing the integer portion in comma-separated format,
nor do any of the other floating-point formats (~E, ~F, ~G).
Conversely, if you give any of the commachar-printing integer formats
(~R, ~D, ~B, ~O, ~X) a floating-point number, it uses ~F (?) instead,
and you lose the "commachar" printing.
So I think the only way to do what "getasso" wanted is something ugly
like this:
> (format nil "~{~:D~3,2F~}" (multiple-value-list (floor 10000.5)))
"10,000.50"
>
or less concisely but also with less consing:
> (multiple-value-bind (i f)
(floor 10000.5)
(format nil "~:D~3,2F" i f))
"10,000.50"
>
Notice that these use the special case of "w=d+1" mentioned in
CLHS "22.3.3.1 Tilde F: Fixed-Format Floating-Point" to suppress
the leading zero of the fraction part:
Leading zeros are not permitted, except that a single zero digit
is output before the decimal point if the printed value is less
than one, and this single zero digit is not output at all if w=d+1.
-Rob
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
····@rpw3.org (Rob Warnock) writes:
> Pascal Bourguignon <···@informatimago.com> wrote:
> +---------------
> | ·······@gmail.com writes:
> | > how to i get comma seperated integer/float point with "Format"
> | > example 10,000.5 - > 10,000.5
> | > what other arguments other than ':D' should be included to cause that
> | > effect.
> | > (format t "~:D,etc,etc" 10000.5)
> |
> | Use the monetary format ~$, which is useful also on non monetary values.
> +---------------
>
> As far as I know [and I searched CLHS "22.3.3.4 Tilde Dollarsign:
> Monetary Floating-Point" pretty closely], monetary format doesn't
> provide for printing the integer portion in comma-separated format,
> nor do any of the other floating-point formats (~E, ~F, ~G).
Indeed, I was wrong. Sorry.
> Conversely, if you give any of the commachar-printing integer formats
> (~R, ~D, ~B, ~O, ~X) a floating-point number, it uses ~F (?) instead,
> and you lose the "commachar" printing.
>
> So I think the only way to do what "getasso" wanted is something ugly
> like this:
>
> > (format nil "~{~:D~3,2F~}" (multiple-value-list (floor 10000.5)))
>
> "10,000.50"
> >
>
> or less concisely but also with less consing:
>
> > (multiple-value-bind (i f)
> (floor 10000.5)
> (format nil "~:D~3,2F" i f))
>
> "10,000.50"
> >
>
> Notice that these use the special case of "w=d+1" mentioned in
> CLHS "22.3.3.1 Tilde F: Fixed-Format Floating-Point" to suppress
> the leading zero of the fraction part:
>
> Leading zeros are not permitted, except that a single zero digit
> is output before the decimal point if the printed value is less
> than one, and this single zero digit is not output at all if w=d+1.
--
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org
On Apr 10, 8:41 pm, ····@rpw3.org (Rob Warnock) wrote:
> Pascal Bourguignon <····@informatimago.com> wrote:
> +---------------| ·······@gmail.com writes:
>
> | > how to i get comma seperated integer/float point with "Format"
> | > example 10,000.5 - > 10,000.5
> | > what other arguments other than ':D' should be included to cause that
> | > effect.
> | > (format t "~:D,etc,etc" 10000.5)
> |
> | Use the monetary format ~$, which is useful also on non monetary values.
> +---------------
>
> As far as I know [and I searched CLHS "22.3.3.4 Tilde Dollarsign:
> Monetary Floating-Point" pretty closely], monetary format doesn't
> provide for printing the integer portion in comma-separated format,
> nor do any of the other floating-point formats (~E, ~F, ~G).
>
> Conversely, if you give any of the commachar-printing integer formats
> (~R, ~D, ~B, ~O, ~X) a floating-point number, it uses ~F (?) instead,
> and you lose the "commachar" printing.
>
> So I think the only way to do what "getasso" wanted is something ugly
> like this:
>
> > (format nil "~{~:D~3,2F~}" (multiple-value-list (floor
Thank Rob and all. Tried and it work.