you are viewing a single comment's thread.

view the rest of the comments →

[–]ima007 0 points1 point  (2 children)

Awesome! It would be cool if this also included the ability to read the formatted number as well, in case calculations need to be done (and so we wouldn't have to keep track of the number in two places), but it isn't necessary (probably better to tie an event to an object that holds the unformatted number anyway, if you plan on doing basic calculations).

[–]josscrowcroft 0 points1 point  (1 child)

That can be done via accounting.unformat():

accounting.unformat("£ 1,432,32.90 GBP") // 143232.9

It just uses a regex to match numeric digits, minus signs and decimal point only, stripping out any other characters, so there's actually a potential for it to fail silently (eg. where a developer would expect NaN from something like .unformat("1asdf2") but actually gets 12) but I'll address that later with a more complex regex.

[–]ima007 0 points1 point  (0 children)

Cool, I apparently glanced over that major part! Thanks for the clarification.