q icon indicating copy to clipboard operation
q copied to clipboard

Number rounding destroying data

Open dkvasnicka opened this issue 9 years ago • 5 comments

When doing a select on a CSV that has a numeric column, "3873194.8699999987" gets rounded to "3873194.87". Please prevent this or introduce a parameter to control it. Thanks!

dkvasnicka avatar Mar 09 '15 20:03 dkvasnicka

Hi @dkvasnicka

This is indeed an issue, and requires adding full support for decimal types.

I already have an intermediate temporary version which allows to force all column types to strings. This has been helpful in one related use case. However, it won't be helpful in your case, unless you're writing the output fields without any computation whatsoever.

If you want it, I'd be glad to send it to you. Just drop me a line over email.

I'm working on abstracting the decimal values issue away (sqlite does not have a real notion of a decimal, so it needs to be handled by q).

Harel

harelba avatar Mar 09 '15 21:03 harelba

Hi and thanks for the prompt response,

In this case I was writing the decimal fields without any computation but other whole-number fields were involved in some computation - so coercing all stuff into string isn't an option.

For now I've solved this using a custom script so this bug isn't a blocker for me.

dkvasnicka avatar Mar 09 '15 22:03 dkvasnicka

@harelba I having a similar issue, a columns with code numbers, some of the numbers start with leading '0', but when i make a query, the command detect that the column is a number, and outputs the number removing the leading 0, what it's incorrect, becuase the code must have all the digits. How i can force 'q' to read all the columns or some of them as strings?

mrsarm avatar Jul 24 '18 23:07 mrsarm

I think this is in fact related to ticket https://github.com/harelba/q/issues/171. The solution is to use at least version 1.6.0 and providing the --as-text option.

bitti avatar Jul 24 '18 23:07 bitti

Thanks @bitti , it worked!

mrsarm avatar Jul 25 '18 01:07 mrsarm