Numbers: leading zeros in text

I have a list of addresses: a text file, utf-8 coding, one line per record, fields in records separated by tab.

Numbers cannot open the file directly: I cannot choose utf-8 before opening, and cannot change it later ("please choose a different encoding"). Thus I use a plain text editor (BBEdit), then copy and paste.

One column is a postal code. Most (but not all!) look like numbers, some start with a zero, e.g. 01280.

I set all columns of a new table to type text.

When pasting, the leading zeros in the post codes are suppressed.

This does not happen pasting a single text item with leading zeros.

Additionally, pasting a single line puts all text in one cell, pasting more than one line splits over columns but supresses the zeros.

This did not happen in version 2.3 nor does it happen in Excel.

Both the opening of utf-8 and the supression of leading zeroes in text are serious bugs.

Have I overlooked some setting or preference somewhere? (Big Sur, Numbers 11.x)


Posted on Nov 7, 2021 3:13 AM

Reply

Similar questions

7 replies

Nov 7, 2021 1:00 PM in response to Badunit

Thanks Badunit.

The source of the file is a php program accessing a data base and outputting a text file. I'll inspect.

However the problem crops up even after passing the file through BBEdit. I'll do some more experiments.

The real bad thing is the leading zeroes. Your sarcasm is appreciated. Apple can be assured that my next computer will run Linux or Windows.


The column in question has a mix of postal codes from many different countries, some using letters, so your suggestion will not help.


Fortunately the data did not contain the character "|". So I first changed all "0" to "|", then pasted it into Numbers, then changed the "|" back to "0" and that worked. Sigh. As I often say: "before we reach the mountains of Artificial Intelligence, we mus cross the desert of the halfwitted devices."


As an aside (mentioned elsewhere) I use plain numbers for dates. Today is 20211107. YYYYMMDD. But I use a custom format to display them: ####-##-##, specifically setting the type to number. Thus 20211107 should be displayed as 2021-11-07 but be a number. When I compare 20211107 with 20210101, Numbers tells me I'm comparing a date with a number, because in one case it uses the displayed value (which of course is always really a string) which it then for a mysterious reason interprets as a date (I never use date formats anywhere ever). Sigh.

Nov 7, 2021 8:47 AM in response to RobertCailliau

I do not know why it won't import the file directly. I often import plain text files (Comma separated and tab separated data). I make them in TextEdit when questions like this come up. BBEdit says they are UTF-8 and Numbers imports them fine and also thinks they are UTF-8. I changed one to UTF-16 in BBEdit and it imported into Numbers no problem, this time the import settings said it was UTF-16. From what I am seeing there doesn't seem to be a general problem importing UTF encoded files.


What is the source of your file? I wonder Numbers is choking on a specific character. If you make a simple test file (formatted as plain text) in TextEdit can you import that?


As for it dropping the leading zeros, Numbers knows exactly what you want and need when importing files so obviously you are wrong to want the leading zeros and it is right to drop them. It knows that those things you think are zip codes are really just numbers and numbers do not have leading zeros so it fixed them for you. Say thank you.


You can select the column and set the format to numeral system with 5 places. That will pad the 5-digit zips with leading zeros. Any that were 9 (or 11) digit zips should have imported okay and are being treated as text. They will be unaffected by this attempt to change their format. If it was a mix of 5 and 9 digits zips, you might want to change the format of the entire column to text so it is consistent. If it was and will only be 5-digit zips, you can leave it as numeral system.

Nov 7, 2021 3:32 PM in response to RobertCailliau

I sometimes think of going back to Windows. I liked Windows 2000. But then I'll get tasked to help set up a new Windows laptop and it is so frustrating I want to tear my hair out. Or my wife's Windows computer will have some weird problem that I have to spend hours scouring the internet trying to solve because nothing is where it should be in Windows and they keep moving and shuffling things around and "reengineering" stuff so most of the advice/instructions on line don't work.


Excel runs on Macs. You can go to that versus jumping to Windows.


If you are often importing this same file (files with the same columns of data), one idea is to copy/paste the data into a blank table and have another table that is full of formulas that fix all the problems. The blank table and the other table would be part of your template, all ready to go. This assumes we can come up with formulas that will fix all the import problems.


I am not having the problem you are having with the dates. I tried those two "dates" with a custom format of ####-##-## and they are numbers for me.

Nov 7, 2021 11:46 PM in response to Badunit

:-)


I know what you mean. The main thing that made me stick to Macs since 1984(!) was the coherence of the interface and the existence of GUI guidlines. But in Big Sur that coherence is gone. This is not the place to make a list, but it is long and amazing. Just one example: when you do not want to save a document you've just changed, depending on the application, you now have to press "Don't save", "Revert changes" or "Delete". Confusing, and the only really valid answer is "Don't save".


The current situation comes from an irresistible urge to change things, even when they are perfectly satisfactory. But if it ain't broke, don't fix it.


Your solution of using anoter table full of formulae to fix the problems had also occurred to me. The formulae would be horrendous.

Excel runs on Macs, but my version is 32bit so no longer works, and I hate to buy a new pack, just for one or two sheets I need to send out. And certainly I do not want subscriptions. I never use Word or PowerPoint.


As to the dates: it is a little more subtle than described.

This formula:

SUMIFS(B,A,">"&C2)

sums the values of the B column when the number in the A column is greater than that in cell C2.

It works OK if A and C contain numbers with automatic format. It fails (but not with an error) if the numbers in column A and the number in cell C2 are formatted as ####-##-## (while still being set to type number).

As an additional little bit of info: in my System Preferences the date format is set to custom with ####-##-##. But note that NONE of my spreadsheets ever used type date in any cell. And that it all worked fine in Numbers 2.x Also when I use the VALUE() function around the comparison cell reference, it works.


But, in the end, those behaviours are bugs. I've reported them and they should be fixed. Or rather should simply not have shown up.

The slogan now seems to be form before function. The first sentence of Apple's description of Numbers starts:

"Create gorgeous spreadsheets with Numbers..."

I don't want them to be gorgeous, I want them to work.


Have a nice day, and thanks for helping me blow off steam.

Nov 8, 2021 11:32 AM in response to RobertCailliau

Badunit, I can't attach a Numbers file, but made a screenshot:



The cells in columns A and B all contain numbers. So do C1 and C2. Their format is ####-##-## but the type is number.

C8 is SUM(A9:A19) and produces correctly 132.

C3 contains

SUMIFS(B,A,">"&VALUE(C$1),A,"<"&VALUE(C$2))

which also works correctly, but if I make it into

SUMIFS(B,A,">"&C$1,A,"<"&C$2)

it tells me that the formula compares a date to a number, and displays 0.

"try it, you'll like it!"

:-)

Nov 8, 2021 2:41 PM in response to RobertCailliau

I see what you mean now with SUMIF. I can't say with conviction what it "should" do. It could ignore all cell formatting and always use the actual values in the cell/ranges. Or it could use the formatted values of the condition and the test-values and try to interpret them. What it shouldn't do is use the formatted value for the condition but not for the test-values.


Edited. I see you already tried VALUE. I hadn't got to that post yet.


Nov 8, 2021 11:55 PM in response to Badunit

I think much of the confusion is historical. Many applications of personal computers were made by people with no formal training in informatics. (see at end) They just started writing code at the top left and down to the end.

It is therefore not surprising that Excel makes the same errors, and so they creep into anything that needs to be compatible.


A well-designed spreadsheet should for each cell distinguish between

the formula (if there is one),

the value,

the type of the value,

the presentation or display of the value (which is always a character string),

the limitations on editing the formula or value.


Formulae should always use the value and its type. Thus my cells have a value that is a number, a type that is a number, but a presentation that does not look like a number. In editing a value, Numbers does revert to showing me a number, i.e. I cannot edit the hyphens.


The SUMIFS should use the value, but they do not. The comparison operator ">" should verify that both sides have the same type. In this case they are of the same type, therefore the implementation of SUMIFS is incorrect. The bug is not present in Numbers 2.x


Further, if a cell refers to one of these number cells with a formula like


= LEFT(A5,3)


that should be reported as an error because the formula tries to get the first three characters of a character string, but A5 contains a number. Something like


=LEFT(DISPLAY(A5),3)


would be acceptable, because it would explicitly refer to the displayed character string. Or, to keep things simple, one might admit implicit use of the display string in certain formulae like LEFT, MID, RIGHT etc. and that should be mentioned in the manual.

But most certainly I should not have to use VALUE inside the SUMIFS.


Robert.


Ignorance that persist:

C-type programmers use "to cast" as "to convert". But the meaning is very different: If I convert an integer to a floating point number, the value is the same but the internal representation changes. If I cast a variable to another type, the internal representation stays the same, a string of bits in memory, but it will be interpreted as of a different type.

Resolution and definition: the difference was first ignored, then it was realised there were actually two different measures, and now they are pixel density (resolution) and resolution (definition).

And so on. Not to speak of syntax.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Numbers: leading zeros in text

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.