lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 30.08.2013 22:42 schröbte Coda Highland:
On Fri, Aug 30, 2013 at 1:29 PM, Choonster TheMage
<choonster.2010@gmail.com> wrote:
On 31 August 2013 06:14, Geoff Smith <spammealot1@live.co.uk> wrote:

I am trying to trim a number string to remove non significant trailing
zeros. So for example

"123.450000000" = "123.45"
"1234500" = "1234500"
"12345.00" = "12345.0"


Try this pattern:

     local stripped = fullNumber:match("^(%d*%.?0?%d-)0*$")

Where fullNumber is the string containing the number that you want to
remove trailing zeroes from.


I have a hesitation on that solution -- if there isn't a decimal
point, that's still going to truncate trailing zeroes, which is
clearly incorrect behavior.

Have you tried? Granted, `0*` is greedy, but so is `%d*`, and currently Lua resolves this ambiguity by matching from left to right (not sure if this is "official" behavior, though).


/s/ Adam


Philipp