wrong number conversion #13

Closed
balexandre opened this Issue Oct 5, 2016 · 4 comments

Projects

None yet

2 participants

@balexandre
balexandre commented Oct 5, 2016 edited

Why does the number 0205e7 gets converted into 2050000000 ? is there an option to avoid conversions and just output the given "strings" ?


@balexandre

here's some data so you can see how the numbers (as code) are being wrongly converted:

"uid";"code";"balance";"initial";"expiry"
18285;1e2641;500;500;04/08/19
14552;000be5;150;150;13/12/18
16398;1e3319;399;399;23/12/18
8047;9535e6;0;150;18/11/18
8193;8e8813;26;600;04/09/18
19095;655e38;200;200;01/10/19
12838;5743e5;94;300;11/12/18
@balexandre balexandre changed the title from wrong number to wrong number conversion Oct 5, 2016
@martindrapeau
Owner

0205e7 is in fact a number 205 x 10^7. It uses the E notation. The conversion is correct according to the spec: http://rfc7159.net/rfc7159#rfc.section.6.

This being said, CSVJSON should not reformat the number but just copy as is. I will fix this.

@balexandre
balexandre commented Oct 6, 2016 edited

to make it correctly and add this as a feature, I would suggest to have a 2nd row where we could express the data types, for example:

"uid";"code";"balance";"initial";"expiry"
"number";"string";"decimal(.)";"decimal(,)";"date(dd/mm/yy)"
18285;1e2641;500;500;04/08/19
14552;000be5;150;150;13/12/18
...

and a checkbox where we could specify if we're using that data-type row or not... we could try with simple conversions like string, decimal(<decimal char>), date(<format>), etc...

would make a way to keep the conversion as you have currently (might be what the user wants in some cases, for example, if they want numeric values), but give you and us the ability to specify what output we want

as a simple example, if those were HEX color codes, without the initial #, every conversion would fail, setting it as string data-type, it would simply do return field."";

As a developer, I'm just giving my 5 cents on the subject...

@martindrapeau martindrapeau added a commit that referenced this issue Oct 7, 2016
@martindrapeau Fix for GitHub issue #13. Added option to parse number values or not …
…to retain original number formatting.

Also added more inline help and clarified options.
da47c1a
@martindrapeau
Owner

I added an option to parse, or not, numbers. For example:
http://www.csvjson.com/csv2json/d3a940ab91487c24c42a3e15b44d6df8

Your proposal to let the user specify types is a good one, but fairly complex. If I get more requests of that type, I will consider it.

Thanks for your help and let me know if the solution above works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment