[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to format a number with thousandth separators?
- From: Zakaria <z4k4ri4@...>
- Date: Thu, 26 Jan 2006 10:01:32 +0700
On 1/26/06, PA <petite.abeille@gmail.com> wrote:
> On Jan 25, 2006, at 09:40, Zakaria wrote:
> > I'm a Lua newbie. What is the best way to do it?
> Very brutal, there must be a better way :)
> function self:formatNumber( aNumber, aLocale )
> if aNumber ~= nil then
> local aString = tostring( math.floor( aNumber ) )
>
> if aString:len() > 3 then
> aString = aString:reverse()
> aString = aString:gsub( "(%d%d%d)", "%1," )
> aString = aString:reverse()
>
> if aString:sub( 1, 1 ) == "," then
> aString = aString:sub( 2 )
> end
> end
>
> return aString
> end
> return nil
> end
Is that lua? what version? I use
> Some alternatives:
> http://www.bigbold.com/snippets/posts/show/693
> http://www.rubygarden.org/ruby?NumericFormat
> Cheers
> --
> PA, Onnay Equitursay
> http://alt.textdrive.com/
Wassallam,
-- Zakaria
z4k4ri4@gmail.com Yahoo!: z4k4ri4
http://zakaria.is-a-geek.org
http://pemula.linux.or.id
Mau invite gmail? japri aja.