Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

How to do thousands grouping in zsh?



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! 



Messages sorted by: Reverse Date, Date, Thread, Author