* How to do thousands grouping in zsh?
@ 2014-09-04 8:52 Han Pingtian
2014-09-04 9:44 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Han Pingtian @ 2014-09-04 8:52 UTC (permalink / raw)
To: zsh-users
Hello,
Looks like builtin printf doesn't support "'" flag. I try to figure out
a method to do the thousands grouping of numbers. It works fine.
num_group()
{
local a
local i
a=(${(s::)1})
i=$((${#a}/3))
for ((;i>0;i--))
do
if [[ -n $a[-i*3-1] ]]
then
a[-i*3]=(, $a[-i*3])
fi
done
print ${(j::)a}
}
Is there any other method?
Thanks in advance!
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to do thousands grouping in zsh?
2014-09-04 8:52 How to do thousands grouping in zsh? Han Pingtian
@ 2014-09-04 9:44 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2014-09-04 9:44 UTC (permalink / raw)
To: zsh-users
On Thu, 04 Sep 2014 16:52:23 +0800
Han Pingtian <hanpt@linux.vnet.ibm.com> wrote:
> Is there any other method?
From 5.0.6, just released.
print $(( [#_3] 299792458 ))
299_792_458
It's always "_" because it's in the same format that's understood on
input. You could postprocess it
print ${$(( [#_3] 299792458 ))//_/,}
pws
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-09-04 9:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-04 8:52 How to do thousands grouping in zsh? Han Pingtian
2014-09-04 9:44 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).