Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent decimal handling #335

Closed
neilotoole opened this issue Nov 20, 2023 · 1 comment
Closed

Inconsistent decimal handling #335

neilotoole opened this issue Nov 20, 2023 · 1 comment
Assignees

Comments

@neilotoole
Copy link
Owner

neilotoole commented Nov 20, 2023

Describe the bug

sq doesn't handle decimal values correctly. It probably treats them as float64, which leads to unexpected results.

See this workflow run: https://github.com/neilotoole/sq/actions/runs/6932116521/job/18855333269#step:6:2345

    db_type_test.go:194: 
        	Error Trace:	D:/a/sq/sq/drivers/sqlite3/db_type_test.go:194
        	Error:      	Not equal: 
        	            	expected: "77.77"
        	            	actual  : "77.77000000000001"

To Reproduce

Seems to happen intermittently in workflows.

Expected behavior

In the example above, 77.77 should always be returned, never 77.77000000000001

sq version

Paste the output of sq version --yaml into the code block below:

# $ sq version --yaml
version: v0.44.0
commit: 69d5402
timestamp: 2023-11-20
latest_version: v0.44.0
host:
  platform: darwin
  arch: arm64
  kernel: Darwin
  kernel_version: 22.6.0
  variant: macOS
  variant_version: 13.6.2

Source details

The workflow example above is with sqlite, but it may happen elsewhere.

Additional context

The problem is almost certainly that sq is using float64 to store decimal values, when it really needs to use a dedicated decimal type, e.g. shopspring/decimal.

@neilotoole neilotoole self-assigned this Nov 20, 2023
neilotoole added a commit that referenced this issue Nov 21, 2023
* Now using a dedicated `decimal.Decimal` type instead of float/string.
@neilotoole
Copy link
Owner Author

This is implemented in sq v0.45.0.

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

No branches or pull requests

1 participant