lua-users home
lua-l archive

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

Eric Tetz wrote:
> On Jan 8, 2008 7:04 AM, Jeff Wise <> wrote:
>> Look at all these possible formats:
>> [snip]
> If you strip out the superfluous characters:
> [snip]
> Or you could use one pattern and test if you caught any of the extra stuff:
>    function match_number(s)
>       s = s:gsub("[$,+%s]", "") -- strip garbage
>       local pre, n, post = s:match("([-(]?)(%d*%.%d+)([CR-]?)")
>       return (pre ~= "" or post ~= "") and -n or n
>    end

A minor quibble...

Any attempt at converting a financial figure to a floating point
representation without scaling gets me really worried... it might
work now, but somewhere down the line, extra processing tacked in
by a later developer trusting the data integrity of the input
layer might cause some values to go off by a wee bit.

In this case, I think Jeff just needs them as strings or lightly
processed strings and I do think not converting the figures is safer.

Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia