TableTool icon indicating copy to clipboard operation
TableTool copied to clipboard

Numeric only cells drop leading 0

Open ianbrennan opened this issue 9 years ago • 10 comments

This is a huge problem with most CSV editing tools, even Microsoft Excel. I often am dealing with large CSV files that have a number of entries consisting of numbers that must retain a leading 0 digit. I understand why it does this from a programming point of view, but it's very frustrating.

ianbrennan avatar Jul 31 '16 18:07 ianbrennan

Also I had this problem, and I did a little investigation, a solution was found that by modifying one line code in CSVReader.m

regex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"^\\s*[+-]?(\[1-9]+\\%@?\\d*|\\*\\%@?\\d+|\[0]+\\%@+\\d*)([eE][+-]?\\d+)?\\s*$",_config.decimalMark,_config.decimalMark,_config.decimalMark] options:0 error:NULL];

Jacob, thanks a lot for this simple and efficient application, could you please update it in the new version.

YWangScience avatar Nov 20 '16 23:11 YWangScience

@YWangScience Could you explain in a bit more detail what your proposed change does?

jakob avatar Nov 21 '16 09:11 jakob

@jakob The logic is if a value has no decimalMark (not a float) and it begins with 0, your program considers it as a string rather than a number. For example, 090618 is a string, shall not be cut to 90618. I simply separated \d to [1-9] and 0, surely you can construct a better regex.

YWangScience avatar Nov 21 '16 19:11 YWangScience

@YWangScience thanks for explaining. This makes a lot of sense! (Reading regex expressions is not so easy....)

Would you like to make a pull request with your changes? (If you do, it would also be a good idea to add test cases to make sure that the proposed changes work, and I don't accidentally break them in the future).

jakob avatar Nov 22 '16 08:11 jakob

@YWangScience Thank you so much! Your help saved me a lot of trouble.

dennishylau avatar Sep 08 '17 06:09 dennishylau

@YWangScience Can you please submit as a pull request.

fulldecent avatar Jul 05 '18 19:07 fulldecent

@jakob thanks for this tool and @YWangScience thanks for your investigation and solution for this issue. Can this fix please be updated into a new version of the product? This is preventing us using teh tool to work with mobile phone numbers, which include a leading zero by default in my country

RichardFoxworthy avatar Feb 25 '19 01:02 RichardFoxworthy

Has this been merged? I just downloaded the app from the App Store and it is still messing up my leading 0's...

MEffing avatar Apr 15 '20 12:04 MEffing

+41 on this. Table tool should not mess with data. This is one of the reasons we use CSV at all. Hoping that @MEffing PR could be merged soon.

kauelima avatar Mar 18 '21 14:03 kauelima

It's 2023 and I can't believe this is still an open issue.

MrKistic avatar Feb 08 '23 11:02 MrKistic