q
q copied to clipboard
Rounding floats is cutting decimals instead rounding
I have been testing q and I've found something that could be an issue.
Issue
When I'm doing something like round(avg(c3),3) when querying, is rounding this 32655,5265 to this 32655,526 instead of expected result: 32655,527.
I think that could be an issue, or should be configurable.
Cheers.
That doesn't seem like a q issue, but like a sqlite issue:
$ sqlite3
sqlite> select round(32655.5265, 3);
32655.526
In fact that might be pretty normal, since decimal fractions can not be exactly represented as floats, the internal representation of 32655.5265 might be less than 32655.5265. Since I don't see any way to cast a value to a decimal in sqlite I guess the easiest workaround is to add a small fraction before the rounding to mitigate any float inaccuracies. I.e. round(avg(c3)+1e-10,3).
Hi @nilpix , as @bitti notes, this is an sqlite3 thing. If enough people would complain about this, I might add a custom round function to q which will work around this.
Thanks for your feedback!