From: Rupert Swarbrick <rswarbrick@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: elisp to put commas a number?
Date: Thu, 12 Jun 2008 17:20:01 +0100 [thread overview]
Message-ID: <g2ribh$iaq$1@news.albasani.net> (raw)
In-Reply-To: c000a850-3545-4bbf-a1c7-bd402f1d1477@79g2000hsk.googlegroups.com
[Dammit, hit 'r' rather than 'f' in Gnus. Sorry "The Quiet Center"
that you'll get this twice]
The Quiet Center <thequietcenter@gmail.com> writes:
> Hello, does anyone have any code to put commas in a number?
> ...
> Here is an example of what I want:
>
> (commify (* 130 70491))
> 9,163,830
'Ow about this?
(defun commify (n &optional comma-char)
(unless comma-char (setq comma-char ","))
(with-temp-buffer
(insert (format "%s" n))
(while (> (- (point)
(line-beginning-position))
(if (>= n 0) 3 4))
(backward-char 3)
(insert comma-char)
(backward-char 1))
(buffer-string)))
Try:
(commify (* 130 70491) ".")
(commify (* -13 70491))
I just wrote it, so fingers crossed it does the right thing! Not sure
whether there's a way to find the locale's choice for comma-char,
though.
Rupert
next prev parent reply other threads:[~2008-06-12 16:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-12 14:36 elisp to put commas a number? The Quiet Center
2008-06-12 16:20 ` Rupert Swarbrick [this message]
2008-06-13 12:29 ` Herbert Euler
2008-06-13 12:36 ` Herbert Euler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='g2ribh$iaq$1@news.albasani.net' \
--to=rswarbrick@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.