masaccio / numbers-parser

Python module for parsing Apple Numbers .numbers files
MIT License
201 stars 14 forks source link

Preferred way to extract text/string only values #44

Closed semireg closed 1 year ago

semireg commented 1 year ago

If a document has cells: 1, 2, 3 with Data Format as Number, what is the best way to extract the values as strings, vs. getting cast to "1.0", "2.0", and "3.0"?

I looked at the cat_numbers source and formatted_value, but I'm still getting "3.0" regardless if I change the Number formatting to something like 7 decimal places. If I change the Data Format to "text" it works as I'd expect.

CleanShot 2022-11-17 at 11 21 57@2x
Numbers version 12.1 (7034.0.86)
numbers-parser       3.9.1
masaccio commented 1 year ago

I think I'd have to call that a bug. numbers-parser should be presenting the data as formatted by Numbers at the very least when using --formatting on the command-line. By default it uses built-in types and Numbers uses floats for that (well decimal128 to be specific).

I'll need to see what the difference is in formatting between something stored as 1.000 and 1.

masaccio commented 1 year ago

I've made updates that enable cat-numbers --formatting to extract the format for decimals. Compare:

% cat-numbers -b tests/data/issue-44.numbers 
1.0,1.0
0.0,0.0
-2.0,-2.0
-100.0,-100.0
-100.0,-100.0
-100.1234,-100.1234
-100.1234,-100.1234
True,False
10000.0,10000.0
1000.125,1000.1234559999999
%  cat-numbers -b --formatting tests/data/issue-44.numbers 
1,1.0000
0,0.0000
-2,-2.00000
-100,100
(100),(100)
-100.1234,100.1234
(100.1234),(100.1234)
TRUE,FALSE
10000,"10,000"
1000.125,1000.12